[Numpy-discussion] Matlab page on scipy wiki

Darren Dale dd55 at cornell.edu
Thu Feb 9 04:24:01 CST 2006


On Thursday 09 February 2006 7:03 am, Darren Dale wrote:
> I have a question about upcasting related to this example:
>
> a with elements less than 0.5 zeroed out:
> Matlab: a .* (a>0.5)
> NumPy: where(a<0.5, 0, a)
>
> I think numpy should be able to do a*a>0.5 as well, but instead one must
> do: a*(a>0.5).astype('i')
>
> Is it desireable to upcast bools in this case? I think so, one could always
> recover the current behavior by doing:
> (a*(a>0.5)).astype('?')

oops:

I should have been doing a*(a>0.5), the order of operations is important. My 
mistake.




More information about the Numpy-discussion mailing list