Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-08 Thread Robert Cimrman
Hi Josef, thanks for the summary! I am responding below, later I will make an enhancement ticket. josef.p...@gmail.com wrote: On Sat, Jun 6, 2009 at 4:42 AM, Neil Crighton neilcrigh...@gmail.com wrote: Robert Cimrman cimrman3 at ntc.zcu.cz writes: Anne Archibald wrote: 1. add a keyword

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-08 Thread Robert Cimrman
Robert Cimrman wrote: Hi Josef, thanks for the summary! I am responding below, later I will make an enhancement ticket. Done, see http://projects.scipy.org/numpy/ticket/1133 r. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-06 Thread Neil Crighton
Robert Cimrman cimrman3 at ntc.zcu.cz writes: Anne Archibald wrote: 1. add a keyword argument to intersect1d assume_unique; if it is not present, check for uniqueness and emit a warning if not unique 2. change the warning to an exception Optionally: 3. change the meaning of the

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-06 Thread josef . pktd
On Sat, Jun 6, 2009 at 4:42 AM, Neil Crighton neilcrigh...@gmail.com wrote: Robert Cimrman cimrman3 at ntc.zcu.cz writes: Anne Archibald wrote: 1. add a keyword argument to intersect1d assume_unique; if it is not present, check for uniqueness and emit a warning if not unique 2. change

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-05 Thread Robert Cimrman
josef.p...@gmail.com wrote: On Fri, Jun 5, 2009 at 1:48 AM, Robert Cimrman cimrm...@ntc.zcu.cz wrote: josef.p...@gmail.com wrote: On Thu, Jun 4, 2009 at 4:30 PM, Gael Varoquaux gael.varoqu...@normalesup.org wrote: On Thu, Jun 04, 2009 at 10:27:11PM +0200, Kim Hansen wrote: in(b) or

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-05 Thread David Warde-Farley
On 4-Jun-09, at 4:38 PM, Anne Archibald wrote: It seems to me that this is the basic source of the problem. Perhaps this can be addressed? I realize maintaining compatibility with the current behaviour is necessary, so how about a multistage deprecation: 1. add a keyword argument to

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Alan G Isaac
a[(a==b[:,None]).sum(axis=0,dtype=bool)] hth, Alan Isaac ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread josef . pktd
On Thu, Jun 4, 2009 at 8:23 AM, Alan G Isaac ais...@american.edu wrote: a[(a==b[:,None]).sum(axis=0,dtype=bool)] this is my preferred way when b is small and has unique elements. if the elements in b are not unique, then be can be replaced by np.unique(b) If b is large this creates a huge

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Alan G Isaac
On Thu, Jun 4, 2009 at 8:23 AM, Alan G Isaac ais...@american.edu wrote: a[(a==b[:,None]).sum(axis=0,dtype=bool)] On 6/4/2009 8:35 AM josef.p...@gmail.com apparently wrote: If b is large this creates a huge intermediate array True enough, but one could then use fromiter: setb = set(b) itr =

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread josef . pktd
On Thu, Jun 4, 2009 at 10:13 AM, Alan G Isaac ais...@american.edu wrote: On Thu, Jun 4, 2009 at 8:23 AM, Alan G Isaac ais...@american.edu wrote: a[(a==b[:,None]).sum(axis=0,dtype=bool)] On 6/4/2009 8:35 AM josef.p...@gmail.com apparently wrote: If b is large this creates a huge intermediate

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Alan G Isaac
On Thu, Jun 4, 2009 at 10:13 AM, Alan G Isaac ais...@american.edu wrote: Or if a stable order is not important (I don't recall if the OP specified), one could just np.intersect1d(a, np.unique(b)) On 6/4/2009 10:50 AM josef.p...@gmail.com apparently wrote: This requires that also `a` has only

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread josef . pktd
On Thu, Jun 4, 2009 at 11:12 AM, Alan G Isaac ais...@american.edu wrote: On Thu, Jun 4, 2009 at 10:13 AM, Alan G Isaac ais...@american.edu wrote: Or if a stable order is not important (I don't recall if the OP specified), one could just np.intersect1d(a, np.unique(b)) On 6/4/2009 10:50 AM

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Alan G Isaac
On 6/4/2009 10:50 AM josef.p...@gmail.com apparently wrote: intersect1d gives set intersection if both arrays have only unique elements (i.e. are sets). I thought the naming is pretty clear: intersect1d(a,b) set intersection if a and b with unique elements intersect1d_nu(a,b) set

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Robert Cimrman
Alan G Isaac wrote: On 6/4/2009 10:50 AM josef.p...@gmail.com apparently wrote: intersect1d gives set intersection if both arrays have only unique elements (i.e. are sets). I thought the naming is pretty clear: intersect1d(a,b) set intersection if a and b with unique elements

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread josef . pktd
On Thu, Jun 4, 2009 at 11:19 AM, Alan G Isaac ais...@american.edu wrote: On 6/4/2009 10:50 AM josef.p...@gmail.com apparently wrote: intersect1d gives set intersection if both arrays have only unique elements (i.e. are sets).  I thought the naming is pretty clear: intersect1d(a,b)   set

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Alan G Isaac
On 6/4/2009 11:29 AM josef.p...@gmail.com apparently wrote: intersect1d is the intersection between sets (which are stored as arrays), just like in the mathematical definition the two sets only have unique elements Hmmm. OK, I see you and Robert believe this. But it does not match the

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread josef . pktd
On Thu, Jun 4, 2009 at 12:32 PM, Alan G Isaac ais...@american.edu wrote: On 6/4/2009 11:29 AM josef.p...@gmail.com apparently wrote: intersect1d  is the intersection between sets (which are stored as arrays), just like in the mathematical definition the two sets only have unique elements

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Alan G Isaac
On 6/4/2009 1:27 PM josef.p...@gmail.com apparently wrote: Note: there are two versions of the docs for np.intersect1d, the currently published docs which describe the actual behavior (for the non-unique case), and the new docs on the doc editor

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread josef . pktd
On Thu, Jun 4, 2009 at 2:58 PM, Alan G Isaac ais...@american.edu wrote: On 6/4/2009 1:27 PM josef.p...@gmail.com apparently wrote: Note: there are two versions of the docs for np.intersect1d, the currently published docs which describe the actual behavior (for the non-unique case), and the new

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Kim Hansen
Concerning the name setmember1d_nu, I personally find it quite verbose and not the name I would expect as a non-insider coming to numpy and not knowing all the names of the more special hidden-away functions and not being a python-wiz either. I think ain(a,b) would be the name I had expected as

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Gael Varoquaux
On Thu, Jun 04, 2009 at 10:27:11PM +0200, Kim Hansen wrote: in(b) or in_iterable(b) method, such that you could do a.in(b) which would return a boolean array of the same shape as a with elements true if the equivalent a members were members in the iterable b. That would really by what I would

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Anne Archibald
2009/6/4 josef.p...@gmail.com: intersect1d should throw a domain error if you give it arrays with non-unique elements, which is not done for speed reasons It seems to me that this is the basic source of the problem. Perhaps this can be addressed? I realize maintaining compatibility with the

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread josef . pktd
On Thu, Jun 4, 2009 at 4:30 PM, Gael Varoquaux gael.varoqu...@normalesup.org wrote: On Thu, Jun 04, 2009 at 10:27:11PM +0200, Kim Hansen wrote: in(b) or in_iterable(b) method, such that you could do a.in(b) which would return a boolean array of the same shape as a with elements true if the

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Gael Varoquaux
On Thu, Jun 04, 2009 at 04:43:39PM -0400, josef.p...@gmail.com wrote: Just using in might promise more than it does, eg. it works only for one dimensional arrays, maybe in1d. With in, Then 'in_1d' I found arraysetops because of unique1d, but I didn't figure out what the subpackage really

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread josef . pktd
On Thu, Jun 4, 2009 at 4:52 PM, Gael Varoquaux gael.varoqu...@normalesup.org wrote: On Thu, Jun 04, 2009 at 04:43:39PM -0400, josef.p...@gmail.com wrote: Just using in might promise more than it does, eg. it works only for one dimensional arrays, maybe in1d. With in, Then 'in_1d' No, if the

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Robert Cimrman
josef.p...@gmail.com wrote: On Thu, Jun 4, 2009 at 2:58 PM, Alan G Isaac ais...@american.edu wrote: On 6/4/2009 1:27 PM josef.p...@gmail.com apparently wrote: Note: there are two versions of the docs for np.intersect1d, the currently published docs which describe the actual behavior (for the

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Robert Cimrman
Kim Hansen wrote: Concerning the name setmember1d_nu, I personally find it quite verbose and not the name I would expect as a non-insider coming to numpy and not knowing all the names of the more special hidden-away functions and not being a python-wiz either. To explain the naming: those

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Robert Cimrman
Anne Archibald wrote: 2009/6/4 josef.p...@gmail.com: intersect1d should throw a domain error if you give it arrays with non-unique elements, which is not done for speed reasons It seems to me that this is the basic source of the problem. Perhaps this can be addressed? I realize

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread Robert Cimrman
josef.p...@gmail.com wrote: On Thu, Jun 4, 2009 at 4:30 PM, Gael Varoquaux gael.varoqu...@normalesup.org wrote: On Thu, Jun 04, 2009 at 10:27:11PM +0200, Kim Hansen wrote: in(b) or in_iterable(b) method, such that you could do a.in(b) which would return a boolean array of the same shape as a

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-04 Thread josef . pktd
On Fri, Jun 5, 2009 at 1:48 AM, Robert Cimrman cimrm...@ntc.zcu.cz wrote: josef.p...@gmail.com wrote: On Thu, Jun 4, 2009 at 4:30 PM, Gael Varoquaux gael.varoqu...@normalesup.org wrote: On Thu, Jun 04, 2009 at 10:27:11PM +0200, Kim Hansen wrote: in(b) or in_iterable(b) method, such that you

[Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-03 Thread Ning Sean
Hi, I want to extract elements of an array (say, a) that are contained in another array (say, b). That is, if a=array([1,1,2,3,3,4]), b=array([1,4]), then I want array([1,1,4]). I did the following but the speed is very slow (maybe because a is very long): c=array([]) for x in b:

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-03 Thread josef . pktd
On Wed, Jun 3, 2009 at 8:29 PM, Ning Sean nings...@gmail.com wrote: Hi, I want to extract elements of an array (say, a) that are contained in another array (say, b). That is, if a=array([1,1,2,3,3,4]), b=array([1,4]), then I want array([1,1,4]). I did the following but the speed is very slow

Re: [Numpy-discussion] extract elements of an array that are contained in another array?

2009-06-03 Thread Ning Sean
Thanks! Tried it and it is about twice as fast as my approach. -Ning On Wed, Jun 3, 2009 at 7:45 PM, josef.p...@gmail.com wrote: On Wed, Jun 3, 2009 at 8:29 PM, Ning Sean nings...@gmail.com wrote: Hi, I want to extract elements of an array (say, a) that are contained in another array (say,