scipy.sparse.

swapaxes#

scipy.sparse.swapaxes(A, axis1, axis2)[source]#

Interchange two axes of an array.

Parameters:
Asparse array
axis1int

First axis.

axis2int

Second axis.

Returns:
a_swappedsparse array in COO format

A copy of the input array with the two identified axes swapped.

Raises:
ValueError

If provided a non-integer or out of range [-N, N-1] axis, where N is A.ndim.

Examples

>>> from scipy.sparse import coo_array, swapaxes
>>> A = coo_array([[[1, 2, 3], [2, 0, 0]]])
>>> A.shape
(1, 2, 3)
>>> swapaxes(A, 1, 2).shape
(1, 3, 2)