log1p

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

逐元素计算 x+1 的自然对数,要求 输入 xSparseCooTensorSparseCsrTensor

数学公式:

\[out = ln(1+x)\]

参数

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

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

返回

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

代码示例

>>> import paddle

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