Suppose you are doing the following in all
import numpy as np
arr = np.arange(9).reshape((3,3))
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
arr.T
array([[0, 3, 6],
[1, 4, 7],
[2, 5, 8]])
arr.transpose()
array([[0, 3, 6],
[1, 4, 7],
[2, 5, 8]])
arr.transpose((1,0))
array([[0, 3, 6],
[1, 4, 7],
[2, 5, 8]])
Used when swapping two axes
arr.swapaxes(1,0)
array([[0, 3, 6],
[1, 4, 7],
[2, 5, 8]])
arr.swapaxes(0,1)
array([[0, 3, 6],
[1, 4, 7],
[2, 5, 8]])
np.dot(arr.T,arr)
array([[45, 54, 63],
[54, 66, 78],
[63, 78, 93]])
Three 2x2 matrices are stacked
arr3d = np.arange(12).reshape((3,2,2))
arr3d
array([[[ 0, 1],
[ 2, 3]],
[[ 4, 5],
[ 6, 7]],
[[ 8, 9],
[10, 11]]])
arr3d[0]
array([[0, 1],
[2, 3]])
1st argument: 0 → Do nothing for 3 2x2 matrices Second argument: Transpose 2 → 2x2 matrix Third argument: 1 → Transpose 2x2 matrix
arr3d.transpose((0,2,1))
array([[[ 0, 2],
[ 1, 3]],
[[ 4, 6],
[ 5, 7]],
[[ 8, 10],
[ 9, 11]]])
Recommended Posts