跳到内容

isinf

测试输入数组 x 的每个元素 x_i,以确定其是否等于正无穷大或负无穷大。

参数

名称 类型 描述 默认值
x

数字数据类型的输入数组。

必需

返回值

名称 类型 描述
out 数组

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

特殊情况

对于实值浮点操作数,

  • 如果 x_i+无穷大-无穷大,则结果为 True
  • 在其余情况下,结果为 False

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

  • 如果 a+无穷大-无穷大,并且 b 是任意值(包括 NaN),则结果为 True
  • 如果 a 是有限数或 NaN,并且 b+无穷大-无穷大,则结果为 True
  • 在其余情况下,结果为 False

示例

>>> a = sparse.COO.from_numpy(np.array([[0, 1], [2, np.inf]]))
>>> o = sparse.isinf(a)
>>> o.todense()
array([[False, False],
       [False,  True]])
源代码位于 sparse/numba_backend/_common.py
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
@_support_numpy
def isinf(x, /):
    """
    Tests each element ``x_i`` of the input array ``x`` to determine if equal to positive or negative infinity.

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

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

    Special Cases
    -------------

    For real-valued floating-point operands,

    - If ``x_i`` is either ``+infinity`` or ``-infinity``, 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`` is either ``+infinity`` or ``-infinity`` and ``b`` is any value (including ``NaN``), the result
        is ``True``.
    - If ``a`` is either a finite number or ``NaN`` and ``b`` is either ``+infinity`` or ``-infinity``, the result
        is ``True``.
    - In the remaining cases, the result is ``False``.

    Examples
    --------
    >>> a = sparse.COO.from_numpy(np.array([[0, 1], [2, np.inf]]))
    >>> o = sparse.isinf(a)  # doctest: +SKIP
    >>> o.todense()  # doctest: +SKIP
    array([[False, False],
           [False,  True]])
    """
    return x.isinf()