bundles / numpy 2.4.3 / numpy / swapaxes
_ArrayFunctionDispatcher
numpy:swapaxes
source: /numpy/_core/fromnumeric.py:552
Signature
def swapaxes(a, axis1, axis2)Summary
Interchange two axes of an array.
Parameters
a: array_likeInput array.
axis1: intFirst axis.
axis2: intSecond axis.
Returns
a_swapped: ndarrayFor NumPy >= 1.10.0, if
ais an ndarray, then a view ofais returned; otherwise a new array is created. For earlier NumPy versions a view ofais returned only if the order of the axes is changed, otherwise the input array is returned.
Examples
import numpy as np 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]]])
Aliases
numpy.swapaxes