﻿ Applied Roots

Lists

Instructor: Applied AI Course Duration: 38 mins

Note: As many Students are having difficulty in understanding we are posting the code snippet of tranposing a matrix with little more details

matrix = [
[1, 2, 3, 4],
[2, 3, 4, 5],
[3, 4, 5, 6]]
transposed = []
for i in range(4):
print("we are going to take the ",i,"th element of each row")
lst = []
for row in matrix:
print("the row we are considering :", row, "and we are going to add", row[i],"to a temporary list")
lst.append(row[i])
print("the ",i,"th column elements = ", i ,"th elements in every row are =", lst)
transposed.append(lst)
print("="*50)
print(transposed)


output

we are going to take the  0 th element of each row
the row we are considering : [1, 2, 3, 4] and we are going to add 1 to a temporary list
the row we are considering : [2, 3, 4, 5] and we are going to add 2 to a temporary list
the row we are considering : [3, 4, 5, 6] and we are going to add 3 to a temporary list
the  0 th column elements =  0 th elements in every row are = [1, 2, 3]
==================================================
we are going to take the  1 th element of each row
the row we are considering : [1, 2, 3, 4] and we are going to add 2 to a temporary list
the row we are considering : [2, 3, 4, 5] and we are going to add 3 to a temporary list
the row we are considering : [3, 4, 5, 6] and we are going to add 4 to a temporary list
the  1 th column elements =  1 th elements in every row are = [2, 3, 4]
==================================================
we are going to take the  2 th element of each row
the row we are considering : [1, 2, 3, 4] and we are going to add 3 to a temporary list
the row we are considering : [2, 3, 4, 5] and we are going to add 4 to a temporary list
the row we are considering : [3, 4, 5, 6] and we are going to add 5 to a temporary list
the  2 th column elements =  2 th elements in every row are = [3, 4, 5]
==================================================
we are going to take the  3 th element of each row
the row we are considering : [1, 2, 3, 4] and we are going to add 4 to a temporary list
the row we are considering : [2, 3, 4, 5] and we are going to add 5 to a temporary list
the row we are considering : [3, 4, 5, 6] and we are going to add 6 to a temporary list
the  3 th column elements =  3 th elements in every row are = [4, 5, 6]
==================================================
[[1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6]]


check this out: https://ideone.com/Z21ysE