import numpy as np
a5 = np.array([[1, 2, 3],[4, 5, 6]])
a = len(a5) # rows of a5
b = len(a5[0]) # columns of a5
a6 = np.zeros([b, a])
for i in range(len(a5)):
for j in range(len(a5[0])):
a6[i][j] = a5[j][i]
But, this is giving me Error :- index 2 is out of bounds for axis 0 with size 2
a, b = a5.shapeis more direct than your use oflen. If you use those variables in the range expressions it should be easier to get the index order right.