nums.numpy.swapaxes

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

Interchange two axes of an array.

This docstring was copied from numpy.swapaxes.

Some inconsistencies with the NumS version may exist.

Parameters
  • a (BlockArray) – Input array.

  • axis1 (int) – First axis.

  • axis2 (int) – Second axis.

Returns

a_swapped – For NumPy >= 1.10.0, if a is an BlockArray, 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.

Return type

BlockArray

Examples

The doctests shown below are copied from NumPy. They won’t show the correct result until you operate get().

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