Michael Hearne wrote:
> Is it possible to use multiple conditionals with the pylab.find() function?
>
> For example, in Matlab, I can do the following:
>
> x = rand(1,10);
> i = find(x > 0.5 & x < 0.9); %returns the indices between 0.5 and 0.9
>
> In Python: (ipython -pylab)
> x = rand(1,10)
>
> None of the following approaches work:
> #i = find(x > 0.5 and x < 0.9)
> #i = find(x > 0.5 && x < 0.9)
> #i = find(x > 0.5 & x < 0.9)
>
> I'm pretty certain there is some other way to do this using a numpy 
> method, and if that's all there is, then I will happily use it.
>
> However, if the goal of the pylab module is to achieve (some level of) 
> compatibility with Matlab, then may I suggest this sort of functionality 
> be added to the pylab.find() function?
>
> Thanks,
>
> Mike
>   

Mike:  Use numpy.logical_and/numpy.logical_or for elementwise logical 
operations. In your case,

find(logical_and(x>0.5,x<0.9))

works, as does using parantheses

find((x > 0.5) & (x < 0.9))

-Jeff



------------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to