Skip to content

Commit 8def026

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 80022cf commit 8def026

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

matrix/transpose_of_matrix.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""""
1+
""" "
22
this program returns the transpose of a given 2-D matrix
33
The transpose of a matrix is a new matrix formed by flipping the original matrix over its diagonal.
44
@@ -13,43 +13,43 @@
1313
[3,9,3]]
1414
1515
"""
16-
def transpose_matrix(matrix: list[list[int]]) ->list[list[int]]:
17-
"""""
16+
17+
18+
def transpose_matrix(matrix: list[list[int]]) -> list[list[int]]:
19+
""" ""
1820
creating a new empty matrix for storing transposed values
1921
number of rows in the matrix=len(matrix)
2022
number of columns =number of elements in the matrix=number of element in 1st row of the matrix=len(matrix[0])
2123
"""
22-
transposed_matrix=[[0]*len(matrix) for _ in range(len(matrix[0]))]
23-
"""
24+
transposed_matrix = [[0] * len(matrix) for _ in range(len(matrix[0]))]
25+
"""
2426
created an empty matrix of dimension len(matrix)*len(matrix[0])
2527
"""
2628
for i in range(len(matrix)):
2729
for j in range(len(matrix[0])):
28-
"""
30+
"""
2931
traversing the matrix element-by-element starting from 1st element of 1st row to last element of last row
3032
1st loop--> traversing through the row
3133
2nd loop--> traversing through the column
3234
by this whole matrix is traversing
3335
34-
"""
35-
transposed_matrix[j][i]=matrix[i][j]
36+
"""
37+
transposed_matrix[j][i] = matrix[i][j]
3638
"""
3739
keeping the values of matrix to resultant matrix in transposed order
3840
for example 2nd element of 3rd row will be 3rd element of 2nd row
3941
1nd element of 2rd row will be 2rd element of 1nd row
40-
likwise diagonal element will reamin intact
42+
likwise diagonal element will reamin intact
4143
42-
"""
43-
#return the transposed_matrix
44+
"""
45+
# return the transposed_matrix
4446
return transposed_matrix
47+
48+
4549
"""
4650
check for main function
4751
give input and call the transpose_matrix () function with matirx as a parameter
4852
"""
49-
if __name__=="__main__":
50-
matrix=[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
53+
if __name__ == "__main__":
54+
matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]
5155
print(transpose_matrix(matrix))
52-
53-
54-
55-

0 commit comments

Comments
 (0)