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

Sign up
Appearance settings

Commit 70cc59d

Browse files
Added function to get identity matrix
1 parent 87d44f9 commit 70cc59d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

‎matrix_operations.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ def __get_dimensions(matrix_1: matrix, matrix_2: Optional[matrix] = None) -> \
2626
else:
2727
return dim_1
2828

29+
# noinspection PyUnusedLocal
30+
@staticmethod
31+
def identity(dimension: int) -> matrix:
32+
identity_m: matrix = [[0 for cols in range(dimension)] for rows in range(dimension)]
33+
for i in range(0, dimension):
34+
identity_m[i][i] = 1
35+
return identity_m
36+
2937
# noinspection PyUnusedLocal
3038
@staticmethod
3139
def addition(matrix_1: matrix, matrix_2: matrix) -> matrix:
@@ -117,3 +125,5 @@ def display(matrix_1: matrix) -> None:
117125
MatrixOperations.display(difference)
118126
print('Multiplication of Matrix 3 & 4:')
119127
MatrixOperations.display(product)
128+
print('Identity Matrix:')
129+
MatrixOperations.display(MatrixOperations.identity(3))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /