Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpy: Maximal Value is NaN

Tags:

python

numpy

My question about Python is really trivial: What do I have to modify that the function max() returns a real value for any compiler?

import numpy as np
a = np.array([-1, 0, 1, np.nan])
# The maximal value is 1. It is not nan!
a.max()

There is the possibility to use the following code but it looks ugly to me:

a[np.logical_not(np.isnan(a))].max()
like image 514
strpeter Avatar asked Jan 17 '26 03:01

strpeter


1 Answers

As was answered by @Divakar using np.nanmax(a) will solve your question.

like image 113
SimonBiggs Avatar answered Jan 19 '26 17:01

SimonBiggs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!