[Numpy-discussion] numpy.random.multinomial() cannot handle zero's
Stefan van der Walt
stefan at sun.ac.za
Mon Aug 27 19:29:56 EDT 2007
Hi Chris
On Mon, Aug 27, 2007 at 11:07:00AM -0700, Christopher Barker wrote:
> Is the kahan_sum closer? -- it should be, though compensated summation
> is really for adding LOTS of numbers, for 4, it's pointless at best.
> Anyway, binary floating point has its errors, and compensated summation
> can help, but it's still not exact for numbers that can't be exactly
> represented by binary.
>
> i.e. if your result is within 15 decimal digits of the exact result,
> that's as good as it gets.
I find this behaviour odd for addition. Under python:
In [7]: 0.8+0.2 > 1.0
Out[7]: False
but using the Pyrex module, it yields true. You can find the code at
http://mentat.za.net/html/refer/somesumbug.tar.bz2
and compile it using
pyrexc sum.pyx ; python setup.py build_ext -i
When you run the test, it illustrates the problem:
Sum: 1.00000000000000000000000000000000000000000000000000
Is greater than 1.0? True
Cheers
Stéfan
More information about the NumPy-Discussion
mailing list