Overview:
-
Positive infinity is greater than any real number.
-
The numpy.isposinf() checks each element of a NumPy array-like whether it is positive infinity. If an element is positive infinity then the result is True. The result is False otherwise. The results are returned in an ndarray containing Boolean values. If the input to the function is a scalar then a single Boolean value is returned.
-
To check for negative infinity, the function isneginf() can be used.
Example:
In the example below the array element at [1][2] is an expression subtracting infinity from infinity which evaluates to "Not a Number" (nan). In mathematics, the operation of subtracting infinity from infinity is undefined as infinity is not a finite number. The expression -numpy.inf-(-numpy.inf) also results in nan.
# Example Python program that tests an ndarray of numbers infArray = numpy.ndarray(shape = (2, 3), dtype = float) infArray[0][0] = 1/0.00000000000000000001 print("Elements of the array:") print("Results of the numpy.isposinf():") |
Output:
Elements of the array: [[1.e+20 inf -inf] [ inf inf nan]] Results of the numpy.isposinf(): [[False True False] [ True True False]] |