[Numpy-discussion] Compound conditional indexing

2009-09-30 Thread Gökhan Sever
Hello,

How to conditionally index an array as shown below :

a = arange(10)
a[5a8]

to get
array([6,7])

I can't do this with where either.

What is the cure for this?

Thanks.

-- 
Gökhan
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Compound conditional indexing

2009-09-30 Thread Joe Kington
There may be a more elegant way, but:

In [2]: a = np.arange(10)

In [3]: a[(a5)  (a8)]
Out[3]: array([6, 7])


On Wed, Sep 30, 2009 at 1:27 PM, Gökhan Sever gokhanse...@gmail.com wrote:

 Hello,

 How to conditionally index an array as shown below :

 a = arange(10)
 a[5a8]

 to get
 array([6,7])

 I can't do this with where either.

 What is the cure for this?

 Thanks.

 --
 Gökhan

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Compound conditional indexing

2009-09-30 Thread Christopher Barker
Gökhan Sever wrote:
 How to conditionally index an array as shown below :
 
 a = arange(10)
 a[5a8]
 
 to get
 array([6,7])

In [56]: a[(5a)  (a8)]
Out[56]: array([6, 7])

not as efficient as it might be, but it works.

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/ORR(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

chris.bar...@noaa.gov
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Compound conditional indexing

2009-09-30 Thread Gökhan Sever
Thanks this works.

My second question how to access a second array using this condition?

I am trying slice another array using a compound condition on the reference
array.

say:

a = 1,2,3,4,5,
b = 20,30,40,50,60

I want to get elements of a only when a = 3,4. I know I need indices but how
?



On Wed, Sep 30, 2009 at 1:32 PM, Joe Kington jking...@wisc.edu wrote:

 There may be a more elegant way, but:

 In [2]: a = np.arange(10)

 In [3]: a[(a5)  (a8)]
 Out[3]: array([6, 7])


 On Wed, Sep 30, 2009 at 1:27 PM, Gökhan Sever gokhanse...@gmail.comwrote:

 Hello,

 How to conditionally index an array as shown below :

 a = arange(10)
 a[5a8]

 to get
 array([6,7])

 I can't do this with where either.

 What is the cure for this?

 Thanks.

 --
 Gökhan

 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion



 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion




-- 
Gökhan
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Compound conditional indexing

2009-09-30 Thread Robert Kern
On Wed, Sep 30, 2009 at 14:40, Gökhan Sever gokhanse...@gmail.com wrote:
 Thanks this works.

 My second question how to access a second array using this condition?

 I am trying slice another array using a compound condition on the reference
 array.

 say:

 a = 1,2,3,4,5,
 b = 20,30,40,50,60

 I want to get elements of a only when a = 3,4. I know I need indices but how
 ?

Did you mean elements of b only where a = 3,4?

b[(a==3) | (a==4)]

-- 
Robert Kern

I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth.
  -- Umberto Eco
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] Compound conditional indexing

2009-09-30 Thread Gökhan Sever
On Wed, Sep 30, 2009 at 2:45 PM, Robert Kern robert.k...@gmail.com wrote:

 On Wed, Sep 30, 2009 at 14:40, Gökhan Sever gokhanse...@gmail.com wrote:
  Thanks this works.
 
  My second question how to access a second array using this condition?
 
  I am trying slice another array using a compound condition on the
 reference
  array.
 
  say:
 
  a = 1,2,3,4,5,
  b = 20,30,40,50,60
 
  I want to get elements of a only when a = 3,4. I know I need indices but
 how
  ?

 Did you mean elements of b only where a = 3,4?

 b[(a==3) | (a==4)]

 --
 Robert Kern

 I have come to believe that the whole world is an enigma, a harmless
 enigma that is made terrible by our own mad attempt to interpret it as
 though it had an underlying truth.
  -- Umberto Eco
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion



Ok, ok got it. Thanks Robert :)

Following is what I have been looking for exactly.

I[1]: a = arange(5)

I[2]: b = arange(5)*10

I[3]: a
O[3]: array([0, 1, 2, 3, 4])

I[4]: b
O[4]: array([ 0, 10, 20, 30, 40])

I[5]: b[(a1)  (a3)]
O[5]: array([20])

I was forgetting the parenthesis, and consequently I was being bitten by

ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()

I am glad that it is not my understanding of logic but the usage of NumPy.

-- 
Gökhan
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion