moveaxis

sparse.moveaxis(a, source, destination)[source]

Move axes of an array to new positions.

Other axes remain in their original order.

Parameters:
  • a (SparseArray) – The array whose axes should be reordered.

  • source (int or List[int]) – Original positions of the axes to move. These must be unique.

  • destination (int or List[int]) – Destination positions for each of the original axes. These must also be unique.

Returns:

Array with moved axes.

Return type:

SparseArray

Examples

>>> import numpy as np
>>> import sparse
>>> x = sparse.COO.from_numpy(np.ones((2, 3, 4, 5)))
>>> sparse.moveaxis(x, (0, 1), (2, 3))
<COO: shape=(4, 5, 2, 3), dtype=float64, nnz=120, fill_value=0.0>