Re: [Numpy-discussion] random integers

2015-12-30 Thread Ralf Gommers
On Thu, Dec 31, 2015 at 6:31 AM, Charles R Harris wrote: > Hi All, > > I've implemented several new random integer functions in #6910 > , to wit > > >- np.random.random_int32 >- np.random.random_int64 >- np.random.random_intp > > These are the

[Numpy-discussion] random integers

2015-12-30 Thread Charles R Harris
Hi All, I've implemented several new random integer functions in #6910 , to wit - np.random.random_int32 - np.random.random_int64 - np.random.random_intp These are the minimum functions that I think we need for the numpy 1.11.0 release, most es

Re: [Numpy-discussion] How to find indices of values in an array (indirect in1d) ?

2015-12-30 Thread Sebastian Berg
On Mi, 2015-12-30 at 20:21 +0100, Nicolas P. Rougier wrote: > In the end, I’ve only the list comprehension to work as expected > > A = [0,0,1,3] > B = np.arange(8) > np.random.shuffle(B) > I = [list(B).index(item) for item in A if item in B] > > > But Mark's and Sebastian's methods do not seem t

Re: [Numpy-discussion] How to find indices of values in an array (indirect in1d) ?

2015-12-30 Thread Peter Creasey
> > In the end, I?ve only the list comprehension to work as expected > > A = [0,0,1,3] > B = np.arange(8) > np.random.shuffle(B) > I = [list(B).index(item) for item in A if item in B] > > > But Mark's and Sebastian's methods do not seem to work... > The function you want is also in the open sourc

Re: [Numpy-discussion] How to find indices of values in an array (indirect in1d) ?

2015-12-30 Thread Nicolas P. Rougier
In the end, I’ve only the list comprehension to work as expected A = [0,0,1,3] B = np.arange(8) np.random.shuffle(B) I = [list(B).index(item) for item in A if item in B] But Mark's and Sebastian's methods do not seem to work... > On 30 Dec 2015, at 19:51, Nicolas P. Rougier wrote: > > > U

Re: [Numpy-discussion] How to find indices of values in an array (indirect in1d) ?

2015-12-30 Thread Nicolas P. Rougier
Unfortunately, this does not handle repeated entries in a. > On 30 Dec 2015, at 19:40, Mark Miller wrote: > > I was not familiar with the .in1d function. That's pretty handy. > > Yes...it looks like numpy.where(numpy.in1d(b, a)) does what you need. > > >>> numpy.where(numpy.in1d(b, a)) > (a

Re: [Numpy-discussion] How to find indices of values in an array (indirect in1d) ?

2015-12-30 Thread Mark Miller
I was not familiar with the .in1d function. That's pretty handy. Yes...it looks like numpy.where(numpy.in1d(b, a)) does what you need. >>> numpy.where(numpy.in1d(b, a)) (array([1, 2, 5, 7], dtype=int64),) It would be interesting to see the benchmarks. On Wed, Dec 30, 2015 at 10:17 AM, Nicolas P

Re: [Numpy-discussion] How to find indices of values in an array (indirect in1d) ?

2015-12-30 Thread Nicolas P. Rougier
Yes, it is the expected result. Thanks. Maybe the set(a) & set(b) can be replaced by np.where[np.in1d(a,b)], no ? > On 30 Dec 2015, at 18:42, Mark Miller wrote: > > I'm not 100% sure that I get the question, but does this help at all? > > >>> a = numpy.array([3,2,8,7]) > >>> b = numpy.array([

Re: [Numpy-discussion] How to find indices of values in an array (indirect in1d) ?

2015-12-30 Thread Nicolas P. Rougier
Thanks, I will make some benchmark and post results. > On 30 Dec 2015, at 17:47, Sebastian Berg wrote: > > On Mi, 2015-12-30 at 17:12 +0100, Nicolas P. Rougier wrote: >> Thanks for the quick answers. I think I will go with the .index and >> list comprehension. >> But if someone finds with a v

Re: [Numpy-discussion] How to find indices of values in an array (indirect in1d) ?

2015-12-30 Thread Mark Miller
I'm not 100% sure that I get the question, but does this help at all? >>> a = numpy.array([3,2,8,7]) >>> b = numpy.array([1,3,2,4,5,7,6,8,9]) >>> c = set(a) & set(b) >>> c #contains elements of a that are in b (and vice versa) set([8, 2, 3, 7]) >>> indices = numpy.where([x in c for x in b])[0] >>>

Re: [Numpy-discussion] How to find indices of values in an array (indirect in1d) ?

2015-12-30 Thread Sebastian Berg
On Mi, 2015-12-30 at 17:12 +0100, Nicolas P. Rougier wrote: > Thanks for the quick answers. I think I will go with the .index and > list comprehension. > But if someone finds with a vectorised solution for the numpy 100 > exercises... > Yeah, I doubt you can get very pretty, though maybe there is

Re: [Numpy-discussion] How to find indices of values in an array (indirect in1d) ?

2015-12-30 Thread Nicolas P. Rougier
Thanks for the quick answers. I think I will go with the .index and list comprehension. But if someone finds with a vectorised solution for the numpy 100 exercises... Nicolas > On 30 Dec 2015, at 16:31, Benjamin Root wrote: > > Maybe use searchsorted()? I will note that I have needed to do

Re: [Numpy-discussion] How to find indices of values in an array (indirect in1d) ?

2015-12-30 Thread Benjamin Root
Maybe use searchsorted()? I will note that I have needed to do something like this once before, and I found that the list comprehension form of calling .index() for each item was faster than jumping through hoops to vectorize it using searchsorted (needing to sort and then map the sorted indices to

Re: [Numpy-discussion] How to find indices of values in an array (indirect in1d) ?

2015-12-30 Thread Andy Ray Terrel
Using pandas one can do: >>> A = np.array([2,0,1,4]) >>> B = np.array([1,2,0]) >>> s = pd.Series(range(len(B)), index=B) >>> s[A].values array([ 1., 2., 0., nan]) On Wed, Dec 30, 2015 at 8:45 AM, Nicolas P. Rougier < nicolas.roug...@inria.fr> wrote: > > I’m scratching my head around a sm

[Numpy-discussion] How to find indices of values in an array (indirect in1d) ?

2015-12-30 Thread Nicolas P. Rougier
I’m scratching my head around a small problem but I can’t find a vectorized solution. I have 2 arrays A and B and I would like to get the indices (relative to B) of elements of A that are in B: >>> A = np.array([2,0,1,4]) >>> B = np.array([1,2,0]) >>> print (some_function(A,B)) [1,2,0] # A[0]

Re: [Numpy-discussion] Dynamic array list implementation

2015-12-30 Thread Nicolas P. Rougier
> On 28 Dec 2015, at 19:58, Chris Barker wrote: > > On Wed, Dec 23, 2015 at 4:01 AM, Nicolas P. Rougier > wrote: > But my implementation is quite slow, especially when you add one item at a > time: > > >>> python benchmark.py > Python list, append 10 items: 0.01161 > Array list, append 1

[Numpy-discussion] Numpy funding update

2015-12-30 Thread Ralf Gommers
Hi all, A quick good news message: OSDC has made a $5k contribution to NumFOCUS, which is split between support for a women in technology workshop and support for Numpy: http://www.numfocus.org/blog/osdc-donates-5k-to-support-numpy-women-in-tech This was a very nice surprise to me, and a first sig