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.

mastisa
  • 1,875
  • 3
  • 21
  • 39
python
  • 55
  • 9
  • 1
    `print(a.shape)` (before and after `transpose()`) might help illustrate what it does. – jedwards Jun 17 '18 at 06:07
  • Yes I already printed this command but how the order of storage is changes?That is what I want to undertand – python Jun 17 '18 at 06:21
  • I already go through the above answers but didn't get the idea – python Jun 17 '18 at 06: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. – hpaulj Jun 17 '18 at 06:44
  • Does it means that my storage order is incorrect? – python Jun 17 '18 at 06:52
  • when I print result it shows different order – python Jun 17 '18 at 06:55
  • Print `a` or `b` doesn't show the 'storage order'. It shows a representation of its multidimensional layout. – hpaulj Jun 17 '18 at 07:08
  • So if I give command np.transpose(2,0,1) how can I explain it in terms of stride? – python Jun 17 '18 at 07:26

0 Answers0