numpy.swapaxes()

numpy.swapaxes

numpy.swapaxes(a, axis1, axis2) [source]

Interchange two axes of an array.

Parameters:

a : array_like

Input array.

axis1 : int

First axis.

axis2 : int

Second axis.

Returns:

a_swapped : ndarray

For Numpy >= 1.10, if a is an ndarray, then a view of a is returned; otherwise a new array is created. For earlier Numpy versions a view of a is returned only if the order of the axes is changed, otherwise the input array is returned.

Examples

>>> x = np.array([[1,2,3]])
>>> np.swapaxes(x,0,1)
array([[1],
       [2],
       [3]])
>>> x = np.array([[[0,1],[2,3]],[[4,5],[6,7]]])
>>> x
array([[[0, 1],
        [2, 3]],
       [[4, 5],
        [6, 7]]])
>>> np.swapaxes(x,0,2)
array([[[0, 4],
        [2, 6]],
       [[1, 5],
        [3, 7]]])

© 2008–2016 NumPy Developers
Licensed under the NumPy License.
https://docs.scipy.org/doc/numpy-1.11.0/reference/generated/numpy.swapaxes.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部