NumPy Logic functions: isfinite() function
numpy.isfinite() function
The isfinite() function is used to test element-wise for finiteness (not infinity or not Not a Number).
The result is returned as a boolean array.
Syntax:
numpy.isfinite(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'isfinite'>
Version: 1.15.0
Parameter:
Name | Description | Required / Optional |
---|---|---|
x | Input values. array_like |
Required |
out | A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned. A tuple (possible only as a keyword argument) must have length equal to the number of outputs. ndarray, None, or tuple of ndarray and None |
Optional |
where | Values of True indicate to calculate the ufunc at that position, values of False indicate to leave the value in the output alone. array_like |
Optional |
**kwargs | For other keyword-only arguments | Required |
Returns:
y : ndarray, bool - True where x is not positive infinity, negative infinity, or NaN; false otherwise. This is a scalar if x is a scalar.
Notes:
Not a Number, positive infinity and negative infinity are considered to be non-finite.
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 the second argument is also supplied when x is a scalar input, or if first and second arguments have different shapes.
NumPy.isfinite() method Example-1:
>>> import numpy as np
>>> np.isfinite(5)
Output:
True
NumPy.isfinite() method Example-2:
>>> import numpy as np
>>> np.isfinite(0)
Output:
True
NumPy.isfinite() method Example-3:
>>> import numpy as np
>>> np.isfinite(np.nan)
Output:
False
NumPy.isfinite() method Example-4:
>>> import numpy as np
>>> np.isfinite(np.inf)
Output:
False
NumPy.isfinite() method Example-5:
>>> import numpy as np
>>> np.isfinite(np.NINF)
Output:
False
NumPy.isfinite() method Example-6:
>>> import numpy as np
>>> np.isfinite([np.log(-1.),1.,np.log(0)])
Output:
array([False, True, False])
NumPy.isfinite() method Example-7:
>>> import numpy as np
>>> x = np.array([-np.inf, 0., np.inf])
>>> y = np.array([5, 5, 5])
>>> np.isfinite(x, y)
Output:
array([0, 1, 0])
NumPy.isfinite() method Example-8:
>>> import numpy as np
>>> x = np.array([-np.inf, 0., np.inf])
>>> y = np.array([5, 5, 5])
>>> np.isfinite(x, y)
>>> y
Output:
array([0, 1, 0])
Python - NumPy Code Editor:
Previous: any() function
Next: isinf() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/numpy/logic-functions/isfinite.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics