0
arr=np.arange(24).reshape((2, 3, 4))
arr.transpose((2,0,1))

what does 2 means 0 means and 1 means over here and how it is related to what we have got as answer?

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]]])
arr.transpose((2,0,1)) <----please explain this tuple
array([[[ 0,  4,  8],
        [12, 16, 20]],

       [[ 1,  5,  9],
        [13, 17, 21]],

       [[ 2,  6, 10],
        [14, 18, 22]],

       [[ 3,  7, 11],
        [15, 19, 23]]])
``````````````````````````````````````````
  • 1
    From the docs [here](https://numpy.org/doc/1.18/reference/generated/numpy.transpose.html): "`axes` By default, reverse the dimensions, otherwise permute the axes according to the values given." In your example, dimension 2 becomes dimension 0, dimension 0 becomes dimension 1, and dimension 1 becomes dimension 2. – BallpointBen Apr 24 '20 at 04:57
  • What's the new shape? (4,2,3). The 4, which was last (2 position) is now first, and the 2 dimensions moved over. It's just a remapping of the dimensions. Note where the 0 1 2 3 sequence is now. – hpaulj Apr 24 '20 at 04:58
  • yes thank you so much @BallpointBen – Taimoor Arif Apr 24 '20 at 05:06

0 Answers0