I'm trying to create a code for transpose an array
I come from Matlab, and I create this code (wich works well):
A = [1,2,3,0,-2,0 ; 0,2,0,1,2,3];
n = size(A);
for i=1:n(2)
for j=1:n(1)
M(i,j) = A(j,i)
end
end
In Python I'm tryng this (using the same logic):
M = [
[1,2,3,0,-2,0],
[0,2,0,1,2,3]
]
LM = (len(M),len(M[0]))
print(LM)
Maux=[[]]
print(Maux)
for i in range(0,LM[1]):
for j in range(0,LM[0]):
Maux[i][j] = M[j][i]
print(Maux)
But when I compile, the error is:
Maux[i][j] = M[j][i] IndexError: list assignment index out of range
And I know using numpy I can create this code as well:
import numpy as np
A = [
[1,2,3,0,-2,0],
[0,2,0,1,2,3]
]
T = np.transpose(A)
print(A)
print(T)
But I need create this code only using for loops, any idea?