Numpy 中的 transpose

# 官方文档描述
numpy.ndarray.transpose
ndarray.transpose(*axes)
Returns a view of the array with axes transposed. 返回轴转置后的数组
For a 1-D array, this has no effect. (To change between column and row vectors, first cast the 1-D array into a matrix object.) # transpose 对一维数组无效
For a 2-D array, this is the usual matrix transpose. For an n-D array, if axes are given, their order indicates how the axes are permuted (see Examples). If axes are not provided and a.shape = (i[0], i[1], … i[n-2], i[n-1]), then a.transpose().shape = (i[n-1], i[n-2], … i[1], i[0]).
# 对二维数组,其实就相当于矩阵的转置
Parameters: axes : None, tuple of ints, or n ints None or no argument: reverses the order of the axes. tuple of ints: i in the j-th place in the tuple means a‘s i-th axis becomes a.transpose()‘s j-th axis. n ints: same as an n-tuple of the same ints (this form is intended simply as a “convenience” alternative to the tuple form) Returns: out : ndarray View of a, with axes suitably permuted. See also ndarray.T Array property returning the array transposed.
何为矩阵转置
在数学上,矩阵是指纵横排列的二维数据表格,最早来自于方程组的系数及常数所构成的方阵。这一概念由19世纪英国数学家凯利首先提出。
设A为m×n阶矩阵(即m行n列),第i 行j 列的元素是a(i,j),即:A=a(i,j)
定义A的转置为这样一个n×m阶矩阵B,满足B=a(j,i),即 b (i,j)=a (j,i)(B的第i行第j列元素是A的第j行第i列元素),记A’=B。(有些书记为    ,这里T为A的上标)
直观来看,将A的所有元素绕着一条从第1行第1列元素出发的右下方45度的射线作镜面反转,即得到A的转置。

>>>
>>> a = np.array([[1, 2], [3, 4]])
>>> a 
array([[1, 2], [3, 4]])
>>> a.transpose()
array([[1, 3], [2, 4]])

>>> a.transpose((1, 0))
array([[1, 3], [2, 4]])
>>> a.transpose(1, 0)
array([[1, 3], [2, 4]])