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)\]
  • 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.


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


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])