[Numpy-discussion] where

Ryan Krauss ryanlists at gmail.com
Thu Apr 13 09:27:06 CDT 2006


Does where return a mask?

If I do
myvect=where((f > 19.5) & (phase > 0),f,phase)
myvect is the same length as f and phase and there is some
modification of the values where the condition is met, but what that
modification is is unclear to me.

If I do
myind=where((f > 19.5) & (phase > 0))
I seem to get the indices of the points where both conditions are met.

I am using version 0.9.5.2043.  I see those kinds of errors about
truth testing an array often, but not in this case.

Thanks,

Ryan

On 4/13/06, Travis Oliphant <oliphant at ee.byu.edu> wrote:
> Ryan Krauss wrote:
>
> >Can someone help me understand the proper use of where?
> >
> >I want to use it like this
> >
> >myvect=where(f>19.5 and phase>0, f, phase)
> >
> >but I seem to be getting or rather than and.
> >
> >
> >
> It is probably your use of the 'and' statement.   Use '&' instead
>
> (f > 19.5) & (phase > 0)
>
> What version are you using.  In numarray and NumPy the use of 'and' like
> this should raise an error if 'f' and/or 'phase' are arrays of more than
> one element.
>
> -Travis
>
>




More information about the Numpy-discussion mailing list