isnan

paddle.sparse. isnan ( x, name=None ) [source]

Return whether every element of input tensor is NaN or not, requiring x to be a SparseCooTensor or SparseCsrTensor.

Parameters
  • x (Tensor) – The input tensor (SparseCooTensor or SparseCsrTensor), it’s data type should be float16, float32, float64, int32, int64.

  • name (str, optional) – Name for the operation (optional, default is None). For more information, please refer to Name.

Returns

A Sparse Tensor with the same shape as x, the bool result which shows every element of x whether it is NaN or not.

Examples

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