transpose

paddle.sparse. transpose ( x, perm, name=None ) [source]

Changes the perm order of x without changing its data, requiring x to be a SparseCooTensor or SparseCsrTensor.

\[out = transpose(x, perm)\]
Parameters
  • x (Tensor) – The input Sparse Tensor with data type float32, float64.

  • perm (list|tuple) – Permute the input according to the data of perm.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

A transposed Sparse Tensor with the same data type as x.

Examples

>>> import paddle

>>> dense_x = paddle.to_tensor([[-2., 0.], [1., 2.]])
>>> sparse_x = dense_x.to_sparse_coo(1)
>>> out = paddle.sparse.transpose(sparse_x, [1, 0])
>>> out
Tensor(shape=[2, 2], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
    indices=[[0, 0]],
    values=[[-2.,  0.],
            [ 1.,  2.]])