[Numpy-discussion] logical priority

Perry Greenfield perry at stsci.edu
Wed Feb 9 10:48:31 EST 2005


Stephen Walton wrote:

> Anyway, we've wandered afar from the main point:  what is the best way 
> to duplicate the functionality of the following MATLAB snippet:
> 
> f = ~isnan(data1) & ~isnan(data2);
> plot(x,data1(f),x,data2(f))
> 
Strictly speaking there is no operator equivalent (you can always use
the ufunc logical_and: f = logical_and(~isnan(data1), ~isnan(data2)) )
(using isnan for the sake of illustration)

I'm not sure if this is wise advice, I point out to people that 
generally speaking, the arguments to the and operator are typically
boolean arrays and for numarray anyway (I forget if it can be different
for Numeric) you can simply use the '&' bitwise operator to the same
effect. No doubt that such use will eventually be misinterpreted 
and someone will provide a non-boolean argument resulting in confusion
(perhaps a mandatory comment is needed in such cases)

No doubt this is a wart from array user's perspectives.

Perry





More information about the NumPy-Discussion mailing list