Hi,

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

>>> -1/20
-1
>>> Numeric.array([-1])[0] / Numeric.array([20])[0]
-1
>>> numarray.array([-1])[0] / numarray.array([20])[0]
-1
>>> numpy.array([-1])[0] / numpy.array([20])[0]
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
that.

Cheers,

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



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Reply via email to