transpose

paddle.sparse. transpose ( x, perm, name=None ) [源代码]

根据 perm 对输入的 x 维度进行重排,但不改变数据, x 必须是多维 SparseTensor 或 COO 格式的 2 维或 3 维 SparseTensor。

\[out = transpose(x, perm)\]

参数

  • x (Tensor) - 输入的 Tensor,数据类型为 float32、float64、int32 或 int64。

  • perm (list|tuple) - perm 长度必须和 x 的维度相同,并依照 perm 中数据进行重排。

  • name (str,可选) - 具体用法请参见 Name,一般无需设置,默认值为 None。

返回

转置后的稀疏 Tensor, 数据类型和压缩格式与 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])
>>> out
Tensor(shape=[2, 2], dtype=paddle.float32, place=Place(cpu), stop_gradient=True,
    indices=[[0, 0]],
    values=[[-2.,  0.],
            [ 1.,  2.]])