[NumPy-Tickets] [NumPy] #2170: Wrong result when calculating the mean masking nan values on a 64 bit system

NumPy Trac numpy-tickets@scipy....
Tue Jun 19 08:32:13 CDT 2012


#2170: Wrong result when calculating the mean masking nan values on a 64 bit
system
---------------------+------------------------------------------------------
 Reporter:  knopfra  |       Owner:  somebody   
     Type:  defect   |      Status:  new        
 Priority:  high     |   Milestone:  Unscheduled
Component:  Other    |     Version:  1.6.1      
 Keywords:           |  
---------------------+------------------------------------------------------
 The array provided as a pickle file at the following link
 [http://dl.dropbox.com/u/30592272/data.pkl.gz] can be used to detect the
 following issue (64 bit Linux system, python 2.7.3, numpy 1.6.1). The
 array has 15606478 elements.

 In [1]: import numpy as np

 In [2]: a = np.load('data.pkl')

 In [3]: np.nanmin(a)[[BR]]
 Out[3]: 4.715836

 In [4]: np.nanmax(a)[[BR]]
 Out[4]: 4.7189121

 In [5]: idx = np.where(np.isfinite(a))

 In [6]: a[idx].mean()[[BR]]
 Out[6]: 4.1792714738680736

 In [7]: from scipy.stats import nanmean

 In [8]: nanmean(a)[[BR]]
 Out[8]: 4.1792714738680727

 The mean value obtained is clearly wrong.
 On a 32 bit system the result is the following:

 In [1]: import numpy as np

 In [2]: a = np.load('data.pkl')

 In [3]: idx = np.where(np.isfinite(a))

 In [4]: a[idx].mean()[[BR]]
 Out[4]: 4.7184738182116019

 and this time the mean value is correct.

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/2170>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list