跳到内容

isnan

测试输入数组 x 的每个元素 x_i,以确定该元素是否为 NaN

参数

名称 类型 描述 默认值
x

具有数值数据类型的输入数组。

必需

返回值

名称 类型 描述
out 数组

一个包含测试结果的数组。返回的数组具有 bool 数据类型。

备注

对于实值浮点操作数,

  • 如果 x_iNaN,结果为 True
  • 在其余情况下,结果为 False

对于复浮点操作数,令 a = real(x_i)b = imag(x_i),且

  • 如果 abNaN,结果为 True
  • 在其余情况下,结果为 False

示例

>>> a = sparse.COO.from_numpy(np.array([[0, 1], [2, np.nan]]))
>>> o = sparse.isnan(a)
>>> o.todense()
array([[False, False],
       [False,  True]])
源代码位于 sparse/numba_backend/_common.py
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
2994
@_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()