NumPy Logic functions: isnan() function
numpy.isnan() function
The isnan() function is used to test element-wise for NaN and return result as a boolean array.
Syntax:
numpy.isnan(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'isnan'>
Version: 1.15.0
Parameter:
Name | Description | Required / Optional |
---|---|---|
x | Input array. 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 or bool - True where x is NaN, false otherwise. This is a scalar if x is a scalar.
Notes:
NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic (IEEE 754).
This means that Not a Number is not equivalent to infinity.
NumPy.isnan() method Example-1:
>>> import numpy as np
>>> np.isnan(np.nan)
Output:
True
NumPy.isnan() method Example-2:
>>> import numpy as np
>>> np.isnan(np.inf)
Output:
False
NumPy.isnan() method Example-3:
>>> import numpy as np
>>> np.isnan([np.log(-2.),2.,np.log(0)])
Output:
array([ True, False, False])
Python - NumPy Code Editor:
Previous: isinf() function
Next: isnat() 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/isnan.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics