scipy.sparse.

matrix_transpose#

scipy.sparse.matrix_transpose(A)[source]#

Return the matrix transpose of A.

Parameters:
Asparse array

Input array.

Returns:
sparse array

The matrix transpose of A.

See also

coo_array.mT

equivalent attribute

coo_array.T

full transposition reversing all dimensions

numpy.matrix_transpose

equivalent function in NumPy

Notes

This is equivalent to A.T for 2-D arrays, and interprets greater dimensional A as a stack of 2-D arrays on which to perform the transpose.

Examples

>>> import numpy as np
>>> from scipy.sparse import coo_array, matrix_transpose
>>> data = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
>>> array = coo_array(data)
>>> array.T.toarray()
array([[[1, 5],
        [3, 7]],

       [[2, 6],
        [4, 8]]])
>>> matrix_transpose(array).toarray()
array([[[1, 3],
        [2, 4]],

       [[5, 7],
        [6, 8]]])