COO.T

COO.T

Returns a new array which has the order of the axes reversed.

Returns

The new array with the axes in the desired order.

Return type

COO

See also

COO.transpose

A method where you can specify the order of the axes.

numpy.ndarray.T

Numpy equivalent property.

Examples

We can change the order of the dimensions of any COO array with this function.

>>> x = np.add.outer(np.arange(5), np.arange(5)[::-1])
>>> x  
array([[4, 3, 2, 1, 0],
       [5, 4, 3, 2, 1],
       [6, 5, 4, 3, 2],
       [7, 6, 5, 4, 3],
       [8, 7, 6, 5, 4]])
>>> s = COO.from_numpy(x)
>>> s.T.todense()  
array([[4, 5, 6, 7, 8],
       [3, 4, 5, 6, 7],
       [2, 3, 4, 5, 6],
       [1, 2, 3, 4, 5],
       [0, 1, 2, 3, 4]])

Note that by default, this reverses the order of the axes rather than switching the last and second-to-last axes as required by some linear algebra operations.

>>> x = np.random.rand(2, 3, 4)
>>> s = COO.from_numpy(x)
>>> s.T.shape
(4, 3, 2)