Python Forum
Difficulty in understanding transpose with a tuple of axis numbers in 3-D
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Difficulty in understanding transpose with a tuple of axis numbers in 3-D
#1
Hi, I know transpose from Linear Algebra courses. Basically just flip columns to rows and vice versa. However, I don't quite understand what is mean by "for arrays with more than 2 dimensions, transpose will accept a tuple of axes numbers to permute the axes".

Does that mean for 1-D array (called vector), taking a transpose of a 1 x n vector turns it into a n x 1 vector and vice versa. As for the 2-D array (called matrix), taking the transpose of a m x n matrix turns it into a n x m matrix and vice versa. However, for higher dimensional arrays such as a 3-D matrix/array, if the parameter for the transpose function is a tuple of axis numbers, transpose just reorder the axes?


How python derived the 2nd matrix in the following example?

In [78]: arr = np.arange(16).reshape((2, 2, 4))                                                     

In [79]: arr                                                                                        
Out[79]: 
array([[[ 0,  1,  2,  3],
        [ 4,  5,  6,  7]],

       [[ 8,  9, 10, 11],
        [12, 13, 14, 15]]])

In [80]: arr.transpose((1, 0, 2))                                                                   
Out[80]: 
array([[[ 0,  1,  2,  3],
        [ 8,  9, 10, 11]],

       [[ 4,  5,  6,  7],
        [12, 13, 14, 15]]])
I read the transpose document but still don't understand it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Having difficulty finding python.h on OS X catsonmars 2 821 Aug-11-2024, 06:18 AM
Last Post: Pedroski55
Shocked Difficulty understanding .moveaxis in Numpy leea2024 2 899 Aug-10-2024, 06:07 AM
Last Post: leea2024
  Having difficulty with threads and input() sawtooth500 13 3,751 Jun-07-2024, 08:40 AM
Last Post: Gribouillis
  Difficulty in adapting duplicates-filter in script ledgreve 5 1,960 Jul-17-2023, 03:46 PM
Last Post: ledgreve
  Difficulty with installation standenman 2 1,927 May-03-2023, 06:39 PM
Last Post: snippsat
  Difficulty with installation standenman 0 1,210 May-02-2023, 08:33 PM
Last Post: standenman
  Sample labels from excel file in order to put them on x-axis and y-axis of a plot hobbyist 11 6,710 Sep-14-2021, 08:29 AM
Last Post: hobbyist
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 4,299 Nov-04-2020, 11:26 AM
Last Post: Aggam
  Transpose a dataset in pandas simhadriraju 1 2,066 Oct-16-2020, 10:44 AM
Last Post: simhadriraju
  Difference Between Figure Axis and Sub Plot Axis in MatplotLib JoeDainton123 2 3,376 Aug-21-2020, 10:17 PM
Last Post: JoeDainton123

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020