Given a 3D array a, I want to call np.tranpose on each of the element in its first index.
For example, given the array:
array([[[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]],
[[2, 2, 2, 2],
[2, 2, 2, 2],
[2, 2, 2, 2]],
[[3, 3, 3, 3],
[3, 3, 3, 3],
[3, 3, 3, 3]])
I want:
array([[[1, 1, 1],
[1, 1, 1],
[1, 1, 1],
[1, 1, 1]],
[[2, 2, 2],
[2, 2, 2],
[2, 2, 2],
[2, 2, 2]],
[[3, 3, 3],
[3, 3, 3],
[3, 3, 3],
[3, 3, 3]]])
Essentially I want to transpose each element inside the array. I tried to reshape it but I can't find a good way of doing it. Looping through it and calling transpose on each would be too slow. Any advice?
transpose
docs. It takes a parameter. Something likea.transpose([0,2,1])
.arr.reshape(3,4,3)
reshape
doesn't work right? It is not the expected output of transposing a matrix.reshape
on[[1,2,3],[4,5,6]]
will give[[1,2],[3,4],[5,6]]
whiletranspose
will give[[1,4],[2,5],[3,6]]
. If input is[[1,1,1],[1,1,1]]
like in example there would be no difference though.