In python, when I want to fill a huge array with consecutive numbers, I use numpy's arange function. However, as soon as numbers start to get big and I convert my array to float32, the numbers seem to jump randomly. As soon as I use float64, everything works as expected, but I want to know, where this error stems from exactly. I suppose, this happens because large numbers can't be represented exactly. However,
numpy.finfo(numpy.float32)
tells me, that the maximum float32
is about 3.4028235e+38
which I am not nearly close to. In my case, the last number up to which everything is fine seems to be
16777216 = 2**24
Can someone tell me, why this is the case?
The code to reproduce the behaviour is for example:
dat = np.arange(64*1026*1026).reshape((64,1026,1026)).astype(np.float32)