11""" "
22this program returns the transpose of a given 2-D matrix
3- The transpose of a matrix is a new matrix formed by flipping the original matrix over its diagonal.
3+ The transpose of a matrix is a new matrix formed by flipping the original
4+ matrix over its diagonal.
45
56In python a matrix is represented by list inside a list
67suppose given matrix A is
@@ -19,6 +20,12 @@ def transpose_matrix(matrix: list[list[int]]) ->list[list[int]]:
1920 number of rows in the matrix=len(matrix)
2021 number of columns =number of elements in the matrix=number of element in 1st row of the matrix=len(matrix[0])
2122 """
23+
24+ # creating a new empty matrix for storing transposed values
25+ # number of rows in the matrix=len(matrix)
26+ # number of columns =number of elements in the matrix=number of element in 1st row of the matrix
27+ # =len(matrix[0])
28+
2229 transposed_matrix = [[0 ]* len (matrix ) for _ in range (len (matrix [0 ]))]
2330 """
2431 created an empty matrix of dimension len(matrix)*len(matrix[0])
@@ -30,6 +37,12 @@ def transpose_matrix(matrix: list[list[int]]) ->list[list[int]]:
3037 1st loop--> traversing through the row
3138 2nd loop--> traversing through the column
3239 by this whole matrix is traversing
40+
41+ # traversing the matrix element-by-element starting from
42+ # 1st element of 1st row to last element of last row
43+ # 1st loop--> traversing through the row
44+ # 2nd loop--> traversing through the column
45+ # by this whole matrix is traversing
3346
3447 """
3548 transposed_matrix [j ][i ]= matrix [i ][j ]
0 commit comments