Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Matrix Transpose using Nested List Comprehension

''' Program to transpose a matrix using list comprehension'''

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

result = [[X[j][i] for j in range(len(X))] for i in range(len(X[0]))]

for r in result:
   print(r)
Source by www.programiz.com #
 
PREVIOUS NEXT
Tagged: #Matrix #Transpose #Nested #List #Comprehension
ADD COMMENT
Topic
Name
9+4 =