Reputation: 5923
I have a 4D numpy array of shape (N x 8 x 24 x 98)
that I need to reshape to the 5D shape (N x 8 x 24 x 7 x 14)
such that the last dimension is split into 2 separate dimensions.
If v_i
is the value for element i
in the last dimension of the old matrix (containing 98 elements), then the values should be ordered as the following in the 2 new dimensions of shape 7 x 14
:
[[v_0, v_1, v_2, v_3, v_4, v_5, v_6],
[v_7, v_8, v_9, v_10, v_11, v_12, v_13],
...]
Performance is not important so the solution could potentially use a for-loop if needed.
Upvotes: 0
Views: 2038
Reputation: 210842
IIUC you can simply reshape your array / matrix:
In [109]: a = np.arange(8*24*98).reshape(8,24,98)
In [110]: a.shape
Out[110]: (8, 24, 98)
In [111]: x = a.reshape(8,24,7,14)
In [112]: x.shape
Out[112]: (8, 24, 7, 14)
Upvotes: 2