isnan

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

返回输入 tensor 的每一个值是否为 +/-NaN,要求 输入 xSparseCooTensorSparseCsrTensor

参数

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

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

返回

多维稀疏 Tensor,每个元素是一个 bool 值,表示输入 x 的每个元素是否为 +/-NaN,稀疏格式与 x 相同 。

代码示例

>>> import paddle
>>> import numpy as np

>>> format = "coo"
>>> np_x = np.asarray([[[0., 0], [1., 2.]], [[0., 0], [3., float('nan')]]])
>>> dense_x = paddle.to_tensor(np_x)

>>> if format == "coo":
...     sparse_x = dense_x.to_sparse_coo(len(np_x.shape))
>>> else:
...     sparse_x = dense_x.to_sparse_csr()
...
>>> sparse_out = paddle.sparse.isnan(sparse_x)
>>> print(sparse_out)
Tensor(shape=[2, 2, 2], dtype=paddle.bool, place=Place(gpu:0), stop_gradient=True,
       indices=[[0, 0, 1, 1],
                [1, 1, 1, 1],
                [0, 1, 0, 1]],
       values=[False, False, False, True ])