What is numpy.isneginf() in Python?
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.
Syntax
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.
Parameters
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. Ifoutis not specified or is None, a freshly-allocated boolean array is returned.
Return value
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
outis not specified, a boolean array is returned. If the element is negative infinity,Trueis returned. Otherwise,Falseis returned. -
If
outis specified and the type is a numerical array, the result is a numerical array. The integer value1is returned if the element is negative infinity; otherwise, the method returns0.
An error occurs in the case of the following:
-
If
xis scalar andoutis specified. -
If
xandouthave different shapes. -
If
xcontains complex values.
Examples
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