import numpy as np
print max([np.nan, 1, 2, 3, 4])
print max([1, 2, 3, 4, np.nan])
print max([1, 2, 3, np.nan, 4])
the first will print nan as list's max value
the second will print 4 as list's max value
the third will print 4 as list's max value
Is there a solution for this problem? Make all math function just ignore nan?
nanmax() to find the maximum values while ignoring nan values, as well as np. argmax() or . argmax() to find the indices of the maximum values. You won't be surprised to learn that NumPy has an equivalent set of minimum functions: np.
numpy. nanmax() function is used to returns maximum value of an array or along any specific mentioned axis of the array, ignoring any Nan value. Syntax : numpy.nanmax(arr, axis=None, out=None, keepdims = no value)
Method 5: Use the max() and def functions to find the largest element in a given list. The max() function prints the largest element in the list.
numpy. amax() will find the max value in an array, and numpy. amin() does the same for the min value.
Use np.nanmax()
to ignore any NaNs:
In [57]: np.nanmax([np.nan, 1, 2, 3, 4])
Out[57]: 4.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With