Hugo V
Hugo V

Reputation: 81

Modify the shape of a numpy array

I have a numpy array of an images dataset of shape: (32, 32, 3, 7000) (height, width, channels, # of images)

but, I want the same dataset with shape: (7000, 32, 32, 3) (# of images, height, width, channels) without altering the images

what can I do? Thanks!


I used: np.moveaxis(X_train, -1, 0)

Upvotes: 0

Views: 58

Answers (1)

Buoy Rina
Buoy Rina

Reputation: 568

Please use np.transpose function (https://numpy.org/doc/stable/reference/generated/numpy.transpose.html)

np.transpose(x, (3, 0, 1,2))

Upvotes: 1

Related Questions