On Wed, Sep 26, 2012 at 4:31 AM, Pierre Haessig <pierre.haes...@crans.org>wrote:

>  Hi,
>
> Just a detail :
>
> Le 26/09/2012 04:29, Paul Tremblay a écrit :
>
> percent = (np.divide(the_cumsum, the_sum)) * 100
>
> This lines doesn't work on my computer (numpy 1.6.2)
>
> Indeed, there is a casting issue :
> In [2]: percent
> Out[2]: array([  0,   0,   0,   0, 100])
>
> However, using the regular "/" operator instead of np.divide gives the
> proper result:
> In [8]: the_cumsum/the_sum*100
> Out[8]: array([  42.10526316,   71.05263158,   90.78947368,   97.36842105,
> 100.        ])
>
> Best,
> Pierre
>
>
Actually, if you are using the latest numpy (the 1.7 beta), that will also
not work unless you are using py3k or did "from __future__ import
division".  Well, actually, using np.divide will always result in integer
division (this may or may not be a bug).

The correct thing to do until we move on to py3k with its "true division"
is to make sure we cast one of the operands as floats:
the_sum.astype('f').  Plus, using '/' is more concise and readable.

Cheers!
Ben Root
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to