Reputation: 35
I have an array of dimension (300, 2, 17, 80) which is 300 samples of 2 images of dimension (17,80). I'd like to reshape the array to feed my CNN such as (300, 17, 80, 2). How can I do that ? Thanks for the support.
Upvotes: 0
Views: 42
Reputation: 227
You can use np.moveaxis for that purpose. For example,
import numpy as np
M = np.zeros((300,2,17,80))
print(M.shape)
M = np.moveaxis(M, 1, -1)
print(M.shape)
The np.moveaxis(M, 1, -1)
call moves the second axis with axis index=1 to the last position by using the axis index=-1.
Upvotes: 1