Python Forum

Full Version: Difficulty in understanding transpose with a tuple of axis numbers in 3-D
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.