Write a Python Program to Transpose a Matrix

Python Program to Transpose a Matrix

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn  Python programming concepts. You can learn Python language at your own speed and time. One can learn concepts of Python language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Python Program to Transpose a Matrix
Python Program to Transpose a Matrix

Write a Python Program to Transpose a Matrix

PROGRAM: Python Program to Transpose a Matrix

/* Python Program to Transpose a Matrix */

# Program to transpose a matrix using a nested loop

X = [[12,7],
[4 ,5],
[3 ,8]]

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 :-

[12, 4, 3]
[7, 5, 8]

Leave a Reply

Your email address will not be published. Required fields are marked *