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 a8ebbe8

Browse filesBrowse files
committed
creating the matrix_utils module
1 parent 8a20eb7 commit a8ebbe8
Copy full SHA for a8ebbe8

File tree

4 files changed

+20
-15
lines changed
Filter options

4 files changed

+20
-15
lines changed

‎README.md

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Python Projects

‎linear-algebra/determinant-computation/determinant.py

Copy file name to clipboardExpand all lines: linear-algebra/determinant-computation/determinant.py
+2-15Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
import numpy as np
2+
from matrix_utils import get_square_matrix
23

3-
def get_matrix():
4-
rows = int(input('Enter the number of rows: '))
5-
cols = rows
6-
7-
print(f'Enter the elements of the matrix {rows}x{cols}')
8-
matrix = []
9-
for i in range(rows):
10-
row = list(map(float, input(f'Row {i+1} (separate element 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-
matrix = get_matrix()
4+
matrix = get_square_matrix()
185

196
try:
207
determinant = np.linalg.det(matrix)
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import numpy as np
2+

‎linear-algebra/matrix_utils.py

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import numpy as np
2+
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)

0 commit comments

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