Re: [Numpy-discussion] Masking an array with another array

2009-08-12 Thread John [H2O]
I suspect I am trying to do something similar... I would like to create a mask where I have data. In essence, I need to return True where x,y is equal to lon,lat I suppose a setmember solution may somehow be more elegant, but this is what I've worked up for now... suggestions? def genData

Re: [Numpy-discussion] Masking an array with another array

2009-04-23 Thread Neil Crighton
gmail.com> writes: > setmember1d is very fast compared to the other solutions for large b. > > However, setmember1d requires that both arrays only have unique elements. > > So it doesn't work if, for example, your first array is a data vector > with member ship in different groups (therefore n

Re: [Numpy-discussion] Masking an array with another array

2009-04-23 Thread josef . pktd
On Thu, Apr 23, 2009 at 1:24 AM, Gökhan SEVER wrote: > Ahaa,, > > Thanks Gaël. That method is more elegance than the previous inputs, and the > simplest of all. > > Although one line of "import this" says: > > There should be one-- and preferably only one --obvious way to do it. > > I always find

Re: [Numpy-discussion] Masking an array with another array

2009-04-22 Thread Gökhan SEVER
Ahaa,, Thanks Gaël. That method is more elegance than the previous inputs, and the simplest of all. Although one line of "import this" says: There should be one-- and preferably only one --obvious way to do it. I always find many different ways of implementing ideas in Python world. Gökhan O

Re: [Numpy-discussion] Masking an array with another array

2009-04-22 Thread Gael Varoquaux
On Wed, Apr 22, 2009 at 04:21:05PM -0500, Gökhan SEVER wrote: >Could you please give me some hints about how to mask an array using >another arrays like in the following example. >In [14]: a = arange(5) >In [15]: a >Out[15]: array([0, 1, 2, 3, 4]) >and my secondary array

Re: [Numpy-discussion] Masking an array with another array

2009-04-22 Thread josef . pktd
On Wed, Apr 22, 2009 at 10:45 PM, Pierre GM wrote: > > On Apr 22, 2009, at 9:03 PM, josef.p...@gmail.com wrote: >> >> I prefer broad casting to list comprehension in numpy: > > Pretty neat! I still dont have the broadcasting reflex. Now, any idea > which one is more efficient in terms of speed? in

Re: [Numpy-discussion] Masking an array with another array

2009-04-22 Thread Pierre GM
On Apr 22, 2009, at 9:03 PM, josef.p...@gmail.com wrote: > > I prefer broad casting to list comprehension in numpy: Pretty neat! I still dont have the broadcasting reflex. Now, any idea which one is more efficient in terms of speed? in terms of temporaries?

Re: [Numpy-discussion] Masking an array with another array

2009-04-22 Thread josef . pktd
On Wed, Apr 22, 2009 at 8:18 PM, Gökhan SEVER wrote: > Yes Pierre, > > I like this one line of elegances in Python a lot. I was thinking that the > answer lies in somewhere in masked array operations, but I proved wrong. > > Thanks for your input on this small riddle. > > Here is another way of do

Re: [Numpy-discussion] Masking an array with another array

2009-04-22 Thread Gökhan SEVER
Yes Pierre, I like this one line of elegances in Python a lot. I was thinking that the answer lies in somewhere in masked array operations, but I proved wrong. Thanks for your input on this small riddle. Here is another way of doing that. (That's what I thought of initially and what Matthias Mic

Re: [Numpy-discussion] Masking an array with another array

2009-04-22 Thread Pierre GM
On Apr 22, 2009, at 5:21 PM, Gökhan SEVER wrote: > Hello, > > Could you please give me some hints about how to mask an array using > another arrays like in the following example. What about that ? numpy.logical_or.reduce([a==i for i in b]) ___ Nump

[Numpy-discussion] Masking an array with another array

2009-04-22 Thread Gökhan SEVER
Hello, Could you please give me some hints about how to mask an array using another arrays like in the following example. In [14]: a = arange(5) In [15]: a Out[15]: array([0, 1, 2, 3, 4]) and my secondary array is "b" In [16]: b = array([2,3]) What I want to do is to mask a with b values and