[Numpy-discussion] where
Travis Oliphant
oliphant at ee.byu.edu
Thu Apr 13 09:39:04 EDT 2006
Ryan Krauss wrote:
>Does where return a mask?
>
>
Only in the second use case...
>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.
>
>
The behavior of
where(condition, for_true, for_false)
is to return an array of the same shape as condition with elements of
for_true where condition is true and
for_false where condition is false.
Thus myvect will contain elements of f where the condition is met and
elements of phase otherwise.
>If I do
>myind=where((f > 19.5) & (phase > 0))
>I seem to get the indices of the points where both conditions are met.
>
>
Yes. That is correct. It is a different use-case... Note, however,
that in the current SVN version of NumPy, this use-case will always
return a tuple of indices (use the nonzero function instead for behavior
that will stay constant). For your 1-d example (I'm guessing it's 1-d)
where will return a length-1 tuple.
>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.
>
>
That is strange. What are the sizes of f and phase?
-Travis
More information about the NumPy-Discussion
mailing list