Skip to content

isnan

Tests each element x_i of the input array x to determine whether the element is NaN.

Parameters:

Name Type Description Default
x

input array with a numeric data type.

required

Returns:

Name Type Description
out array

an array containing test results. The returned array has data type bool.

Notes

For real-valued floating-point operands,

  • If x_i is NaN, the result is True.
  • In the remaining cases, the result is False.

For complex floating-point operands, let a = real(x_i), b = imag(x_i), and

  • If a or b is NaN, the result is True.
  • In the remaining cases, the result is False.

Examples:

>>> a = sparse.COO.from_numpy(np.array([[0, 1], [2, np.nan]]))
>>> o = sparse.isnan(a)
>>> o.todense()
array([[False, False],
       [False,  True]])
Source code in sparse/numba_backend/_common.py
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
@_support_numpy
def isnan(x, /):
    """
    Tests each element ``x_i`` of the input array ``x`` to determine whether the element is ``NaN``.

    Parameters
    ----------
    x: array
        input array with a numeric data type.

    Returns
    -------
    out: array
        an array containing test results. The returned array has data type ``bool``.

    Notes
    -----

    For real-valued floating-point operands,

    - If ``x_i`` is ``NaN``, the result is ``True``.
    - In the remaining cases, the result is ``False``.

    For complex floating-point operands, let ``a = real(x_i)``, ``b = imag(x_i)``, and

    - If ``a`` or ``b`` is ``NaN``, the result is ``True``.
    - In the remaining cases, the result is ``False``.

    Examples
    --------
    >>> a = sparse.COO.from_numpy(np.array([[0, 1], [2, np.nan]]))
    >>> o = sparse.isnan(a)
    >>> o.todense()  # doctest: +NORMALIZE_WHITESPACE
    array([[False, False],
           [False,  True]])
    """

    return x.isnan()