Feb-11-2020, 06:03 AM
(This post was last modified: Feb-11-2020, 06:03 AM by new_to_python.)
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?
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.
