File tree 2 files changed +7
-28
lines changed
Filter options
2 files changed +7
-28
lines changed
Original file line number Diff line number Diff line change 1
- import numpy as np
2
- from matrix_utils import non_square_matrix
3
-
4
- first_matrix = non_square_matrix ()
5
- second_matrix = non_square_matrix ()
6
-
7
- if first_matrix .shape [1 ] != second_matrix .shape [0 ]:
8
- print ('The number of columns in the first matrix must be equal to the number of rows in the second matrix' )
9
- else :
10
- product = np .dot (first_matrix , second_matrix )
11
- print (f'[first matrix] x [second matrix]: { product } ' )
Original file line number Diff line number Diff line change 1
1
import numpy as np
2
2
3
3
4
- def get_square_matrix ():
5
- rows = int (input ('Enter the number of rows: ' ))
6
- cols = rows
7
-
8
- matrix = []
9
- for i in range (rows ):
10
- row = list (map (float , input (f'Row { i + 1 } (separate elements with space): ' ).split ()))
11
- if len (row ) != cols :
12
- raise ValueError ('Number of elements does not match the number of columns!' )
13
- matrix .append (row )
14
-
15
- return np .array (matrix )
16
-
17
4
18
- def non_square_matrix ():
5
+ def determine_matrix ():
19
6
rows = int (input ('Enter the number of rows: ' ))
20
7
cols = int (input ('Enter the number of cols: ' ))
21
-
22
8
matrix = []
23
9
for i in range (rows ):
24
- row = list (map (float , input (f'Row { i + 1 } : ' ).split ()))
10
+ row = list (map (float , input (f'Row { i + 1 } (separate elements with space: ): ' ).split ()))
11
+ if len (row ) != cols :
12
+ raise ValueError (f'An error occurred! Row{ i + 1 } should have { cols } elements' )
13
+
25
14
matrix .append (row )
26
15
27
- return np .array (matrix )
16
+ matrix = np .array (matrix )
17
+
28
18
You can’t perform that action at this time.
0 commit comments