Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bd4cba2

Browse filesBrowse files
committed
update matrix utils
1 parent f1dcfb5 commit bd4cba2
Copy full SHA for bd4cba2

File tree

2 files changed

+7
-28
lines changed
Filter options

2 files changed

+7
-28
lines changed
-11Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +0,0 @@
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}')

‎linear-algebra/matrix_utils.py

Copy file name to clipboard
+7-17Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
import numpy as np
22

33

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-
174

18-
def non_square_matrix():
5+
def determine_matrix():
196
rows = int(input('Enter the number of rows: '))
207
cols = int(input('Enter the number of cols: '))
21-
228
matrix = []
239
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+
2514
matrix.append(row)
2615

27-
return np.array(matrix)
16+
matrix = np.array(matrix)
17+
2818

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.