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 43a9fe5

Browse filesBrowse files
Create transpose_of_matrix.py
1 parent 9605dcb commit 43a9fe5
Copy full SHA for 43a9fe5

File tree

1 file changed

+22
-0
lines changed
Filter options

1 file changed

+22
-0
lines changed

‎programs/transpose_of_matrix.py

Copy file name to clipboard
+22Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.