此函数互换数组的两个轴,对于1.10之后的NumPy版本,将返回交换数组的视图,该函数采用以下参数。
numpy.swapaxes(arr, axis1, axis2)
Sr.No. | Parameter & 描述 |
---|---|
1 |
arr 要交换其轴的输入数组 |
2 |
axis1 与第一个轴对应的int |
3 |
axis2 与第二个轴对应的int |
# It creates a 3 dimensional ndarray import numpy as np a=np.arange(8).reshape(2,2,2) print 'The original array:' print a print '\n' # now swap numbers between axis 0 (along depth) and axis 2 (along width) print 'The array after applying the swapaxes function:' print np.swapaxes(a, 2, 0)
其输出如下-
The original array: [[[0 1] [2 3]] [[4 5] [6 7]]] The array after applying the swapaxes function: [[[0 4] [2 6]] [[1 5] [3 7]]]
参考链接
https://www.learnfk.com/numpy/numpy-swapaxes.html
标签:数组,NumPy,无涯,np,swapaxes,print,array,numpy From: https://blog.51cto.com/u_14033984/7893395