Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is max and min of numpy array nan?

What could be the reason, why the max and min of my numpy array is nan? I checked my array with:

for i in range(data[0]):
    if data[i] == numpy.nan:
        print("nan")    

And there is no nan in my data. Is my search wrong? If not: What could be the reason for max and min being nan?

like image 628
Jackie Avatar asked Oct 29 '25 05:10

Jackie


1 Answers

Here you go:

import numpy as np

a = np.array([1, 2, 3, np.nan, 4])

print(f'a.max() = {a.max()}')
print(f'np.nanmax(a) = {np.nanmax(a)}')

print(f'a.min() = {a.min()}')
print(f'np.nanmin(a) = {np.nanmin(a)}')

Output:

a.max() = nan
np.nanmax(a) = 4.0
a.min() = nan
np.nanmin(a) = 1.0
like image 153
Balaji Ambresh Avatar answered Oct 31 '25 12:10

Balaji Ambresh