Python’s numpy.isneginf()
is used to test if an element is negative infinity or not. It tests an array element-wise and returns a boolean array as the output.
numpy.isneginf
is declared as follows:
numpy.isneginf(x, out=None)
In the syntax above, x
is the non-optional parameter, and out
is the optional parameter.
The numpy.isneginf()
method takes the following compulsory parameter:
x
[array-like] - input array.The numpy.isneginf()
method takes the following optional parameter:
out
[array_like, optional] - represents the location into which the output of the method is stored. If out
is not specified or is None, a freshly-allocated boolean array is returned.numpy.isneginf
returns a boolean array with the same dimensions as x
. The method returns True
/False
or 0
/1
depending on the following factors:
If out
is not specified, a boolean array is returned. If the element is negative infinity, True
is returned. Otherwise, False
is returned.
If out
is specified and the type is a numerical array, the result is a numerical array. The integer value 1
is returned if the element is negative infinity; otherwise, the method returns 0
.
An error occurs in the case of the following:
If x
is scalar and out
is specified.
If x
and out
have different shapes.
If x
contains complex values.
The example below shows the use of numpy.isneginf()
on the elements a
and b
:
import numpy as npa = -np.infb = np.infprint (np.isneginf(a))print (np.isneginf(b))
The following example shows the use of numpy.isneginf()
on the array arr1
when out
is not specified:
import numpy as nparr1 = np.array([2, -np.inf, 0, np.nan])print (np.isneginf(arr1))
The following example shows the use of numpy.isneginf()
on the array arr2
when out
is specified:
import numpy as nparr2 = np.array([-np.inf, 2, 0])out = np.array([1,1,1])print (np.isneginf(arr2,out))
Free Resources