Skip to content

Commit 43a9fe5

Browse files
Create transpose_of_matrix.py
1 parent 9605dcb commit 43a9fe5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

programs/transpose_of_matrix.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Matrix(object):
2+
def __init__(self,mat = None):
3+
self.mat = mat
4+
5+
def get_matrix(self) -> list:
6+
return self.mat
7+
8+
def transpose(self) -> list:
9+
if self.mat:
10+
try:
11+
return list(zip(*self.mat))
12+
except Exception as e:
13+
return f"Failed to convert transpose because {e}"
14+
mat = [
15+
[1,2,3],
16+
[4,5,6],
17+
[7,8,9]
18+
]
19+
20+
matrix_obj = Matrix(mat)
21+
print(f"Original Matrix is : \n {matrix_obj.get_matrix()}")
22+
print(f"Transpose of above matrix is : \n {matrix_obj.transpose()}")

0 commit comments

Comments
 (0)