Transposing

The transpose function reverses the dimensions of an array:

In [80]: trans_array = np.arange(0,24).reshape(4, 6)
In [82]: trans_array
Out[82]:
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]])
In [83]: trans_array.T
Out[83]:
array([[ 0, 6, 12, 18],
[ 1, 7, 13, 19],
[ 2, 8, 14, 20],
[ 3, 9, 15, 21],
[ 4, 10, 16, 22],
[ 5, 11, 17, 23]])

The following result is obtained on applying transpose on a multidimensional array:

In [84]: trans_array = np.arange(0,24).reshape(2, 3, 4)
In [85]: trans_array.T.shape
Out[85]: (4, 3, 2)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset