1

I have a 4-D Numpy array of dimensions 96x96x3x1000 - these correspond to an image dataset that I have imported : 1000 images each of 96X96 pixels and RGB values for each pixel.

However, I need to iterate over flattened arrays for each image, ie. only a 2-D array [1000][96*96*3]. I managed to transform the given array by first doing

    a.reshape(-1,a.size[3])

and then assigning each column to an image using a loop. I wanted to ask if there is a simpler/slicing method for interchanging the ordering of ndarrays ?

Thanks

1 Answer 1

2

You can change the ordering of the axes using numpy.swapaxes

a.reshape(-1,1000).swapaxes(0,1)

or simply tranposing it

a.reshape(-1,1000).T

You can also change the ordering of the axis at the beginning with numpy.transpose and then apply reshape

a.transpose([3,0,1,2]).reshape(1000,-1)
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.