[Numpy-discussion] Negative division and numpy scalars

Francesc Altet faltet at carabos.com
Mon Sep 25 10:23:04 CDT 2006


I have been bitten by a subtlety in numpy scalar divisions. The next
exposes the issue:

>>> -1/20
>>> Numeric.array([-1])[0] / Numeric.array([20])[0]
>>> numarray.array([-1])[0] / numarray.array([20])[0]
>>> numpy.array([-1])[0] / numpy.array([20])[0]

After some digging, I've found that Python and C follow different
conventions for doing this negative division: Python do a floor of the
result, while C truncates it. As numpy scalar operations seems to be
implemented in C, it seems that it follows the C convention and
truncates the result.

In fact, I like this behaviour of NumPy scalars (at least, when I'm
aware of it!), but I thought it would be nice to warn other people about


>0,0<   Francesc Altet     http://www.carabos.com/
V   V   Cárabos Coop. V.   Enjoy Data

More information about the Numpy-discussion mailing list