numpy.isinf(x[, out])

Shows which elements of the input are positive or negative infinity. Returns a numpy boolean scalar or array resulting from an element-wise test for positive or negative infinity.


x : array_like

input values

y : array_like, optional

An array with the same shape as x to store the result.


y : {ndarray, bool}

For scalar input data, the result is a new numpy boolean with value True if the input data is positive or negative infinity; otherwise the value is False.

For array input data, the result is an numpy boolean array with the same dimensions as the input and the values are True if the corresponding element of the input is positive or negative infinity; otherwise the values are False. If the second argument is supplied then an numpy integer array is returned with values 0 or 1 corresponding to False and True, respectively.

See also

Shows which elements are negative infinity.
Shows which elements are positive infinity.
Shows which elements are Not a Number (NaN).
Shows which elements are not: Not a number, positive and negative infinity


Numpy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754). This means that Not a Number is not equivalent to infinity. Also that positive infinity is not equivalent to negative infinity. But infinity is equivalent to positive infinity.

Errors result if second argument is also supplied with scalar input or if first and second arguments have different shapes.

Numpy’s definitions for positive infinity (PINF) and negative infinity (NINF) may be change in the future versions.


>>> np.isinf(np.inf)
>>> np.isinf(np.nan)
>>> np.isinf(np.NINF)
>>> np.isinf([np.inf, -np.inf, 1.0, np.nan])
array([ True,  True, False, False], dtype=bool)
>>> x=np.array([-np.inf, 0., np.inf])
>>> y=np.array([2,2,2])
>>> np.isinf(x,y)
array([1, 0, 1])
>>> y
array([1, 0, 1])

Previous topic


Next topic


This Page

Quick search