flopscope.numpy.swapaxes
fnp.swapaxes(a, axis1, axis2)[flopscope source][numpy source]
Interchange two axes of an array.
Adapted from NumPy docs np.swapaxes
Cost
0
Flopscope Context
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.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 flopscope.numpy as fnp
>>> x = flops.array([[1,2,3]])
>>> flops.swapaxes(x,0,1)
array([[1],
[2],
[3]])>>> x = flops.array([[[0,1],[2,3]],[[4,5],[6,7]]])
>>> x
array([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])>>> flops.swapaxes(x,0,2)
array([[[0, 4],
[2, 6]],
[[1, 5],
[3, 7]]])