pow

paddle.sparse. pow ( x, factor, name=None ) [源代码]

逐元素计算 x 的幂函数,幂的系数为 factor,要求 输入 xSparseCooTensorSparseCsrTensor

数学公式:

\[out = x^{factor}\]

参数

  • x (SparseTensor) - 输入的稀疏 Tensor,可以为 Coo 或 Csr 格式,数据类型为 float32、float64。

  • factor (float|int) - 幂函数的系数,可以为 float 或 int。

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

返回

多维稀疏 Tensor, 数据类型和稀疏格式与 x 相同 。

代码示例

>>> import paddle

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