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
  Difficulty in adapting duplicates-filter in script ledgreve 5 862 Jul-17-2023, 03:46 PM
Last Post: ledgreve
  Difficulty with installation standenman 2 961 May-03-2023, 06:39 PM
Last Post: snippsat
  Difficulty with installation standenman 1 624 May-02-2023, 09:29 PM
Last Post: sudoku6
  Sample labels from excel file in order to put them on x-axis and y-axis of a plot hobbyist 11 4,300 Sep-14-2021, 08:29 AM
Last Post: hobbyist
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 2,793 Nov-04-2020, 11:26 AM
Last Post: Aggam
  Transpose a dataset in pandas simhadriraju 1 1,431 Oct-16-2020, 10:44 AM
Last Post: simhadriraju
  Difference Between Figure Axis and Sub Plot Axis in MatplotLib JoeDainton123 2 2,460 Aug-21-2020, 10:17 PM
Last Post: JoeDainton123
  Difficulty installing Pycrypto KipCarter 4 11,943 Feb-10-2020, 07:54 PM
Last Post: snippsat
  How to get first line of a tuple and the third item in its tuple. Need Help, Anybody? SukhmeetSingh 5 3,182 May-21-2019, 11:39 AM
Last Post: avorane
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,707 May-09-2019, 12:19 PM
Last Post: Pleiades

Forum Jump:

User Panel Messages

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