Site icon Machine Learning Projects

Python Program to Transpose a Matrix – 2023

Machine Learning Projects

Hey guys, in this blog we will see a Python Program to Transpose a Matrix.

Code

# Python Program to Transpose a Matrix

X = [[21,9],
    [14 ,3],
    [32 ,1]]

result = [[0,0,0],
         [0,0,0]]

# iterate through rows
for i in range(len(X)):
   # iterate through columns
   for j in range(len(X[0])):
       result[j][i] = X[i][j]

for r in result:
   print(r)

Output

[21, 14, 32]
[9, 3, 1]

Check out our other python programming examples

Exit mobile version