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, wrote: > On Wed, Jun 3, 2009 at 8:29 PM, Ning Sean 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,

Re: [Numpy-discussion] [RFR] NpzFile tweaks (Re: Making NpzFiles behave more like dictionaries.)

2009-06-03 Thread David Warde-Farley
On 3-Jun-09, at 5:01 PM, Pauli Virtanen wrote: > > Btw, are you able to change the status of the ticket to > "needs_review"? > I think this should be possible for everyone, and not restricted to > admins, but I'm not 100% sure... Sorry, yes I am. I had just forgotten. David ___

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 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 (maybe because

Re: [Numpy-discussion] field names on numpy arrays

2009-06-03 Thread josef . pktd
On Wed, Jun 3, 2009 at 8:25 PM, wrote: > On Wed, Jun 3, 2009 at 7:56 PM,   wrote: >> On Wed, Jun 3, 2009 at 7:33 PM, Pierre GM wrote: >>> >>> On Jun 3, 2009, at 7:23 PM, Robert Kern wrote: >>> On Wed, Jun 3, 2009 at 18:20, Pierre GM wrote: > > > Or, as all fields have the same

[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: c=append(c,a[

Re: [Numpy-discussion] field names on numpy arrays

2009-06-03 Thread josef . pktd
On Wed, Jun 3, 2009 at 7:56 PM, wrote: > On Wed, Jun 3, 2009 at 7:33 PM, Pierre GM wrote: >> >> On Jun 3, 2009, at 7:23 PM, Robert Kern wrote: >> >>> On Wed, Jun 3, 2009 at 18:20, Pierre GM wrote: Or, as all fields have the same dtype:  >>> a_array.view(dtype=('f',len(a

Re: [Numpy-discussion] field names on numpy arrays

2009-06-03 Thread josef . pktd
On Wed, Jun 3, 2009 at 7:33 PM, Pierre GM wrote: > > On Jun 3, 2009, at 7:23 PM, Robert Kern wrote: > >> On Wed, Jun 3, 2009 at 18:20, Pierre GM wrote: >>> >>> >>> Or, as all fields have the same dtype: >>> >>>  >>> a_array.view(dtype=('f',len(a_array.dtype))) >>> array([[ 0.,  1.,  2.,  3.,  4.]

Re: [Numpy-discussion] field names on numpy arrays

2009-06-03 Thread Pierre GM
On Jun 3, 2009, at 7:23 PM, Robert Kern wrote: > On Wed, Jun 3, 2009 at 18:20, Pierre GM wrote: >> >> >> Or, as all fields have the same dtype: >> >> >>> a_array.view(dtype=('f',len(a_array.dtype))) >> array([[ 0., 1., 2., 3., 4.], >>[ 1., 2., 3., 4., 5.]], dtype=float32) >> >>

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread josef . pktd
On Wed, Jun 3, 2009 at 7:21 PM, Pierre GM wrote: > > On Jun 3, 2009, at 7:00 PM, Robert Kern wrote: > >> On Wed, Jun 3, 2009 at 17:58,   wrote: >>> Do you have an opinion about whether  .view(ndarray_subclass) or >>> __array_wrap__ is the more appropriate return wrapper for function >>> such as th

Re: [Numpy-discussion] field names on numpy arrays

2009-06-03 Thread Robert Kern
On Wed, Jun 3, 2009 at 18:20, Pierre GM wrote: > > On Jun 3, 2009, at 5:03 PM, Robert Kern wrote: > >> On Wed, Jun 3, 2009 at 15:26,   wrote: >>> 2009/6/3 Stéfan van der Walt : Hi Jon 2009/6/3 D2Hitman : > I understand record arrays such as: > a_array = > np.array([(0.,1

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread Pierre GM
On Jun 3, 2009, at 7:00 PM, Robert Kern wrote: > On Wed, Jun 3, 2009 at 17:58, wrote: >> Do you have an opinion about whether .view(ndarray_subclass) or >> __array_wrap__ is the more appropriate return wrapper for function >> such as the ones in stats? > > __array_wrap__ would be more appropri

Re: [Numpy-discussion] field names on numpy arrays

2009-06-03 Thread Pierre GM
On Jun 3, 2009, at 5:03 PM, Robert Kern wrote: > On Wed, Jun 3, 2009 at 15:26, wrote: >> 2009/6/3 Stéfan van der Walt : >>> Hi Jon >>> >>> 2009/6/3 D2Hitman : I understand record arrays such as: a_array = np.array([(0.,1.,2.,3.,4.),(1.,2.,3.,4.,5.)],dtype=[('a','f'), ('b','

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread Robert Kern
On Wed, Jun 3, 2009 at 17:58, wrote: > Do you have an opinion about whether  .view(ndarray_subclass) or > __array_wrap__ is the more appropriate return wrapper for function > such as the ones in stats? __array_wrap__ would be more appropriate. It's what ufuncs use. -- Robert Kern "I have come

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread josef . pktd
On Wed, Jun 3, 2009 at 5:55 PM, Robert Kern wrote: > On Wed, Jun 3, 2009 at 16:31,   wrote: >> On Wed, Jun 3, 2009 at 5:18 PM, Christopher Barker >> wrote: >>> josef.p...@gmail.com wrote: Ok, I didn't know numpy can have structured matrices, >>> >>> well, matrices are a subclass of nd-arrays

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread Robert Kern
On Wed, Jun 3, 2009 at 17:53, wrote: > Is len(z.dtype) > 0   the best way to find out whether an array has a > structured dtype? (z.dtype.names is not None) is better. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread Stéfan van der Walt
2009/6/3 Robert Kern : > On Wed, Jun 3, 2009 at 16:31,   wrote: >> I'm very happy with plain numpy arrays, but to handle different data >> types in scipy.stats, I'm still trying to figure out how views and >> structured arrays work. And I'm still confused. > > .view() is used two different ways, an

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread josef . pktd
On Wed, Jun 3, 2009 at 5:57 PM, Christopher Barker wrote: > josef.p...@gmail.com wrote: >> I'm very happy with plain numpy arrays, but to handle different data >> types in scipy.stats, I'm still trying to figure out how views and >> structured arrays work. And I'm still confused. > > OK, I'd stay

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread Robert Kern
On Wed, Jun 3, 2009 at 16:31, wrote: > On Wed, Jun 3, 2009 at 5:18 PM, Christopher Barker > wrote: >> josef.p...@gmail.com wrote: >>> Ok, I didn't know numpy can have structured matrices, >> >> well, matrices are a subclass of nd-arrays, so they support it, but it's >> probably not the least bit

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread Christopher Barker
josef.p...@gmail.com wrote: > I'm very happy with plain numpy arrays, but to handle different data > types in scipy.stats, I'm still trying to figure out how views and > structured arrays work. And I'm still confused. OK, I'd stay away from matrix then, no need to add that confusion >>From the us

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread josef . pktd
On Wed, Jun 3, 2009 at 5:18 PM, Christopher Barker wrote: > josef.p...@gmail.com wrote: >> Ok, I didn't know numpy can have structured matrices, > > well, matrices are a subclass of nd-arrays, so they support it, but it's > probably not the least bit useful. > > See my earlier post to see how to d

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread Christopher Barker
josef.p...@gmail.com wrote: > Ok, I didn't know numpy can have structured matrices, well, matrices are a subclass of nd-arrays, so they support it, but it's probably not the least bit useful. See my earlier post to see how to do what I think you want. You may not want a matrix anyway -- a 2-d a

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread Robert Kern
On Wed, Jun 3, 2009 at 16:06, wrote: > On Wed, Jun 3, 2009 at 4:58 PM, Robert Kern wrote: >> On Wed, Jun 3, 2009 at 15:23,   wrote: >> import numpy as np >> x = np.array([(0.0, 1.0, 2.0, 3.0, 4.0), (1.0, 2.0, 3.0, 4.0, 5.0)], >>>     dtype=[('a', '>> ('e', '>> >> xvm = x.view(np.matr

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread josef . pktd
On Wed, Jun 3, 2009 at 4:58 PM, Robert Kern wrote: > On Wed, Jun 3, 2009 at 15:23,   wrote: > import numpy as np > x = np.array([(0.0, 1.0, 2.0, 3.0, 4.0), (1.0, 2.0, 3.0, 4.0, 5.0)], >>     dtype=[('a', '> ('e', '> > xvm = x.view(np.matrix) > xvm >> matrix([[(0.0, 1.0, 2.0, 3.0, 4

Re: [Numpy-discussion] field names on numpy arrays

2009-06-03 Thread Robert Kern
On Wed, Jun 3, 2009 at 15:26, wrote: > 2009/6/3 Stéfan van der Walt : >> Hi Jon >> >> 2009/6/3 D2Hitman : >>> I understand record arrays such as: >>> a_array = >>> np.array([(0.,1.,2.,3.,4.),(1.,2.,3.,4.,5.)],dtype=[('a','f'),('b','f'),('c','f'),('d','f'),('e','f')]) >>> do this with field names.

Re: [Numpy-discussion] [RFR] NpzFile tweaks (Re: Making NpzFiles behave more like dictionaries.)

2009-06-03 Thread Pauli Virtanen
Wed, 03 Jun 2009 16:05:51 -0400, David Warde-Farley wrote: > On 2-Jun-09, at 3:06 PM, Pauli Virtanen wrote: > >> +0 >> >> I don't see any drawbacks, and the implementation looks good. > > Thanks Pauli. I realized I was missing values() and itervalues() (though > I can't conceive of a scenario wh

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread Robert Kern
On Wed, Jun 3, 2009 at 15:23, wrote: import numpy as np x = np.array([(0.0, 1.0, 2.0, 3.0, 4.0), (1.0, 2.0, 3.0, 4.0, 5.0)], >     dtype=[('a', ' ('e', ' xvm = x.view(np.matrix) xvm > matrix([[(0.0, 1.0, 2.0, 3.0, 4.0), (1.0, 2.0, 3.0, 4.0, 5.0)]], >       dtype=[('a', ' ('e',

Re: [Numpy-discussion] another view puzzle

2009-06-03 Thread Christopher Barker
josef.p...@gmail.com wrote: import numpy as np x = np.array([(0.0, 1.0, 2.0, 3.0, 4.0), (1.0, 2.0, 3.0, 4.0, 5.0)], > dtype=[('a', ' ('e', ' xvm = x.view(np.matrix) xvm > matrix([[(0.0, 1.0, 2.0, 3.0, 4.0), (1.0, 2.0, 3.0, 4.0, 5.0)]], >dtype=[('a', ' ('e', 'http:/

Re: [Numpy-discussion] field names on numpy arrays

2009-06-03 Thread josef . pktd
2009/6/3 Stéfan van der Walt : > Hi Jon > > 2009/6/3 D2Hitman : >> I understand record arrays such as: >> a_array = >> np.array([(0.,1.,2.,3.,4.),(1.,2.,3.,4.,5.)],dtype=[('a','f'),('b','f'),('c','f'),('d','f'),('e','f')]) >> do this with field names. >> a_array['a'] = array([ 0.,  1.], dtype=float

[Numpy-discussion] another view puzzle

2009-06-03 Thread josef . pktd
>>> import numpy as np >>> x = np.array([(0.0, 1.0, 2.0, 3.0, 4.0), (1.0, 2.0, 3.0, 4.0, 5.0)], dtype=[('a', '>> xvm = x.view(np.matrix) >>> xvm matrix([[(0.0, 1.0, 2.0, 3.0, 4.0), (1.0, 2.0, 3.0, 4.0, 5.0)]], dtype=[('a', '>> xvm*2 matrix([[(0.0, 1.0, 2.0, 3.0, 4.0, 0.0, 1.0, 2.0, 3.0,

[Numpy-discussion] [RFR] NpzFile tweaks (Re: Making NpzFiles behave more like dictionaries.)

2009-06-03 Thread David Warde-Farley
On 2-Jun-09, at 3:06 PM, Pauli Virtanen wrote: > +0 > > I don't see any drawbacks, and the implementation looks good. Thanks Pauli. I realized I was missing values() and itervalues() (though I can't conceive of a scenario where I'd use them myself, I guess some code might expect them). Also I

[Numpy-discussion] setmember1d_nu

2009-06-03 Thread Neil Crighton
Hi all, I posted this message couple of days ago, but gmane grouped it with an old thread and it hasn't shown up on the front page. So here it is again... I'd really like to see the setmember1d_nu function in ticket 1036 get into numpy. There's a patch waiting for review that including tests: h

Re: [Numpy-discussion] field names on numpy arrays

2009-06-03 Thread Stéfan van der Walt
Hi Jon 2009/6/3 D2Hitman : > I understand record arrays such as: > a_array = > np.array([(0.,1.,2.,3.,4.),(1.,2.,3.,4.,5.)],dtype=[('a','f'),('b','f'),('c','f'),('d','f'),('e','f')]) > do this with field names. > a_array['a'] = array([ 0.,  1.], dtype=float32) > however i seem to lose simple opera

Re: [Numpy-discussion] field names on numpy arrays

2009-06-03 Thread Pierre GM
On Jun 3, 2009, at 11:06 AM, D2Hitman wrote: > > Hi, > > I would like to have an object/class that acts like array of floats > such as: > a_array = numpy.array([[0.,1.,2.,3.,4.],[1.,2.,3.,4.,5.]]) > but i would like to be able to slice this array by some header > dictionary: > header_dict = {

[Numpy-discussion] field names on numpy arrays

2009-06-03 Thread D2Hitman
Hi, I would like to have an object/class that acts like array of floats such as: a_array = numpy.array([[0.,1.,2.,3.,4.],[1.,2.,3.,4.,5.]]) but i would like to be able to slice this array by some header dictionary: header_dict = {'a':0,'b':1,'c':2,'d':3,'e':4} such that i could use a_array['a'],

Re: [Numpy-discussion] Problem with correlate

2009-06-03 Thread rob steed
> I wonder if xcorrelate would be a better name than acorrelate? I think it would. ___ Numpy-discussion mailing list Numpy-discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion