Issue
Given an array of shape 3,2,2
np.array([[[1,2],[3,4]],[[5,6],[7,8]],[[9,10],[11,12]]])
I would like to reshape it into shape 2,2,3
.
Downstream, this reshape data will be processed in MATLAB, and for some reason, the MATLAB-Package require the array to be shaped 2,2,3
.
In MATLAB, the expected output should be
val(:,:,1) =
1 2
3 4
val(:,:,2) =
5 6
7 8
val(:,:,3) =
9 10
11 12
Simply reshaping arr.reshape(2,2,3)
does not produced what I intend it to be.
Update: @hpaulj proposal produced
val(:,:,1) =
1 3
2 4
val(:,:,2) =
5 7
6 8
val(:,:,3) =
9 11
10 12
Solution
I believe you are looking for:
np.moveaxis(x, 0, 2)
Your original shape is (3, 2, 2). This line moves axis[0] and rolls it over to axis[2] (shifting the other 2 axes left). And so you get:
>>> x[:, :, 0]
array([[1, 2],
[3, 4]])
Answered By - rudolfovic
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.