11"""
22finding tanspose of the given matrix
3- The transpose of a matrix is a new matrix formed by
4- flipping the original matrix over its main diagonal,
3+ The transpose of a matrix is a new matrix formed by
4+ flipping the original matrix over its main diagonal,
55effectively interchanging its rows and columns
66suppose A=[[1,2,3],
77 [4,5,6],
16163.copy the elements in oppposite order of the traversl
1717i.e. trans[j][i]=matrix[i][j]
1818"""
19+
20+
1921def transpose (matrix ):
20- #create a null matrix of same dimension of given matrix
21- trans = [[0 ]* len (matrix ) for _ in range (len (matrix [0 ]))]
22+ # create a null matrix of same dimension of given matrix
23+ trans = [[0 ] * len (matrix ) for _ in range (len (matrix [0 ]))]
2224 for i in range (len (matrix )):
23- #row wise traversal
25+ # row wise traversal
2426 for j in range (len (matrix [0 ])):
25- #column wise traversal
26- trans [j ][i ]= matrix [i ][j ]
27- #copying the elements in null matrix
27+ # column wise traversal
28+ trans [j ][i ] = matrix [i ][j ]
29+ # copying the elements in null matrix
2830 return trans
29- #checking for main function
30- if __name__ == "__main__" :
31- #matrix(given)
32- mat = [[1 , 2 , 3 ],[4 , 5 , 6 ]]
33- #call the function with mat as parameter
34- print (transpose (mat ))
3531
3632
37-
38-
33+ # checking for main function
34+ if __name__ == "__main__" :
35+ # matrix(given)
36+ mat = [[1 , 2 , 3 ], [4 , 5 , 6 ]]
37+ # call the function with mat as parameter
38+ print (transpose (mat ))
0 commit comments