0

I have an numpy-array with 32 x 32 x 3 pictures with X_train.shape: (32, 32, 3, 73257). However, I would like to have the following array-shape: (73257, 32, 32, 3).

How can I accomplish this?

0

3 Answers 3

2

There are two ways to archive this either np.reshape(x, ndims) or np.transpose(x, dims).

For pictures I propose np.transpose(x, dims) which can be applied using X_train = np.transpose(X_train, (3,0,1,2)).

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, this is correct. np.reshape did destroy the images, np.transpose worked as suggested :-)
1
np.reshape(X_train, (73257, 32, 32, 3))

https://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.reshape.html

1 Comment

Better check that on a small sample. Transpose is right if you want to preserve images.
1

I think you want to do a transpose

>>> a = np.array([[1, 2], [3, 4]])
>>> a
array([[1, 2],
       [3, 4]])
>>> a.transpose()
array([[1, 3],
       [2, 4]])
>>> a.transpose((1, 0))
array([[1, 3],
       [2, 4]])
>>> a.transpose(1, 0)
array([[1, 3],
       [2, 4]])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.