0

I am trying to understand how numpy.transpose command works.

a=np.arange(24).reshape(2,3,4)

According to my understanding numpy stores data like this

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

so there are two samples and 4 channels. In simple math language transpose means convert rows into columns and columns into rows. But how following command works

b= np.transpose(a,(1,0,2))

I have go through the documentation and also questions posted to this website related to this command. But still its not clear to me. can someone please explain this permutation of axes according to the storage pattern that I mentioned above.

8
  • 1
    print(a.shape) (before and after transpose()) might help illustrate what it does. Commented Jun 17, 2018 at 6:07
  • Yes I already printed this command but how the order of storage is changes?That is what I want to undertand Commented Jun 17, 2018 at 6:21
  • I already go through the above answers but didn't get the idea Commented Jun 17, 2018 at 6:27
  • numpy actually stores the data in a flat array, and maps the multidimensional indices onto that using the shape and strides attributes. transpose just changes those attributes, and hence the mapping. It doesn't change the storage. Commented Jun 17, 2018 at 6:44
  • Does it means that my storage order is incorrect? Commented Jun 17, 2018 at 6:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.