[Numpy-discussion] large float32 array issue

Vincent Schut schut@sarvision...
Wed Nov 3 03:54:36 CDT 2010


Hi, I'm running in this strange issue when using some pretty large 
float32 arrays. In the following code I create a large array filled with 
ones, and calculate mean and sum, first with a float64 version, then 
with a float32 version. Note the difference between the two. NB the 
float64 version is obviously right :-)



In [2]: areaGrid = numpy.ones((11334, 16002))
In [3]: print(areaGrid.dtype)
float64
In [4]: print(areaGrid.shape, areaGrid.min(), areaGrid.max(), 
areaGrid.mean(), areaGrid.sum())
((11334, 16002), 1.0, 1.0, 1.0, 181366668.0)


In [5]: areaGrid = numpy.ones((11334, 16002), numpy.float32)
In [6]: print(areaGrid.dtype)
float32
In [7]: print(areaGrid.shape, areaGrid.min(), areaGrid.max(), 
areaGrid.mean(), areaGrid.sum())
((11334, 16002), 1.0, 1.0, 0.092504406598019437, 16777216.0)


Can anybody confirm this? And better: explain it? Am I running into a 
for me till now hidden ieee float 'feature'? Or is it a bug somewhere?

Btw I'd like to use float32 arrays, as precision is not really an issue 
in this case, but memory usage is...


This is using python 2.7, numpy from git (yesterday's checkout), on arch 
linux 64bit.

Best,
Vincent.



More information about the NumPy-Discussion mailing list