On Donnerstag 20 Dezember 2007, Christopher Barker wrote:
> > In [9]: print where( (logical_or(a<1, b<3)), b,c)
> > [4 2 2 1]
> > (Think of the Zen.)
>
> I'm not sure the Zen answers this one for us.
As you have guessed correctly, I was thinking of "explicit is better than
implicit".
> It's real
Hans Meine wrote:
>> where( (a<1 or b<3), b,c)
>
> Now + and | have been proposed to you, but it looks to me as if the "correct
> way" would be logical_or. All solutions give the same result, but logical_or
> better expresses what you're trying to do:
>
> In [9]: print where( (logical_or(a<1,
Am Sonntag, 16. Dezember 2007 20:10:41 schrieb Ross Harder:
> What's the correct way to do something like this?
>
> a=array( (0,1,1,0) )
> b=array( (4,3,2,1) )
> c=array( (1,2,3,4) )
>
> where( (a<1 or b<3), b,c)
Now + and | have been proposed to you, but it looks to me as if the "correct
way" wo
"or" is logical or. You want "|" which is bitwise/elementwise or. Also,
watch the order of operations -- | has higher precedence than <.
Thus, you want
where( (a<1) | (b<3), b,c)
Ross Harder wrote:
> What's the correct way to do something like this?
>
> a=array( (0,1,1,0) )
> b=array( (4,3,2,1)
use '+' instead of 'or' for bool arrays.
In [8]: numpy.where((a<1) + (b<3), b, c)
Out[8]: array([4, 2, 2, 1])
hth,
L.
On Dec 16, 2007 8:10 PM, Ross Harder <[EMAIL PROTECTED]> wrote:
>
> What's the correct way to do something like this?
>
> a=array( (0,1,1,0) )
> b=array( (4,3,2,1) )
> c=array(
What's the correct way to do something like this?
a=array( (0,1,1,0) )
b=array( (4,3,2,1) )
c=array( (1,2,3,4) )
where( (a<1 or b<3), b,c)
Python throws a ValueError
I would expect to get an array that looks like
[4,2,2,1] I think
Thanks,
Ross