0

I have a numpy array: all_data=(10000,3072) where each cell in array is data of a 32*32*3 image. When the data in the cell is formatted as:

np.transpose(np.reshape(image_data,(3, 32,32)), (1,2,0)) 

the real image is displayed (using plt.imshow or any such libraries) . Now i want to transform all_data such that the shape of all_data is (10000,32,32,3) How can i do this?

1
  • what is image_data? Is it the same as all_data or is it something else? Commented Aug 1, 2017 at 23:48

1 Answer 1

1

You could try this, (the same reshaping process but keep the first dimension untouched):

all_data.reshape(10000, 3, 32, 32).transpose(0,2,3,1)

Example:

all_data = np.arange(24).reshape(2,12)

Target reshape it to (2,2,2,3):

all_data
# array([[ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11],
#        [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]])

Reshape one element of the data:

all_data[0].reshape(3,2,2).transpose(1,2,0)
# array([[[ 0,  4,  8],
#         [ 1,  5,  9]],

#        [[ 2,  6, 10],
#         [ 3,  7, 11]]])

Reshape it all together:

all_data.reshape(2,3,2,2).transpose(0,2,3,1)[0]
# array([[[ 0,  4,  8],
#         [ 1,  5,  9]],

#        [[ 2,  6, 10],
#         [ 3,  7, 11]]])
Sign up to request clarification or add additional context in comments.

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.