Skip to content

isinf

Tests each element x_i of the input array x to determine if equal to positive or negative infinity.

Parameters:

Name Type Description Default
x

input array of a numeric data type.

required

Returns:

Name Type Description
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)
>>> o.todense()
array([[False, False],
       [False,  True]])
Source code in sparse/numba_backend/_common.py
2914
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
@_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()