Re: [Numpy-discussion] From Python to Numpy

2016-12-31 Thread Nicolas P. Rougier
> I’ve seen vectorisation taken to the extreme, with negative consequences in > terms of both speed and readability, in both Python and MATLAB codebases, so > I would suggest some discussion / wisdom about when not to vectorise. I agree and there is actually a warning in the introduction abou

Re: [Numpy-discussion] From Python to Numpy

2016-12-30 Thread Nicolas P. Rougier
lysis to close squares. Nicolas > > > >> 23 дек. 2016 г., в 12:14, Kiko написал(а): >> >> >> >> 2016-12-22 17:44 GMT+01:00 Nicolas P. Rougier : >> >> Dear all, >> >> I've just put online a (kind of) book on Numpy and more spec

Re: [Numpy-discussion] Casting to np.byte before clearing values

2016-12-27 Thread Nicolas P. Rougier
Yes, clearing is not the proper word but the "trick" works only work for 0 (I'll get the same result in both cases). Nicolas > On 27 Dec 2016, at 20:52, Chris Barker wrote: > > On Mon, Dec 26, 2016 at 1:34 AM, Nicolas P. Rougier > wrote: > > I'm try

Re: [Numpy-discussion] Casting to np.byte before clearing values

2016-12-26 Thread Nicolas P. Rougier
Thanks for the explanation Sebastian, makes sense. Nicolas > On 26 Dec 2016, at 11:48, Sebastian Berg wrote: > > On Mo, 2016-12-26 at 10:34 +0100, Nicolas P. Rougier wrote: >> Hi all, >> >> >> I'm trying to understand why viewing an array as by

[Numpy-discussion] Casting to np.byte before clearing values

2016-12-26 Thread Nicolas P. Rougier
Hi all, I'm trying to understand why viewing an array as bytes before clearing makes the whole operation faster. I imagine there is some kind of special treatment for byte arrays but I've no clue. # Native float Z_float = np.ones(100, float) Z_int = np.ones(100, int) %timeit Z_fl

[Numpy-discussion] From Python to Numpy

2016-12-22 Thread Nicolas P. Rougier
Dear all, I've just put online a (kind of) book on Numpy and more specifically about vectorization methods. It's not yet finished, has not been reviewed and it's a bit rough around the edges. But I think there are some material that can be interesting. I'm specifically happy with the boids exa

[Numpy-discussion] Useless but tricky exercise

2016-11-03 Thread Nicolas P. Rougier
Hi all, Given an array V that is a view of a base B, I was wondering if it is possible to find a (string) index such that `V = B[index]` For example: ``` B = np.arange(8*8).reshape(8,8) V = B[::2,::2] index = find_view(B,V) print(index) "::2,::2" print(np.allclose(V, eval("B[%s]" % index))) T

[Numpy-discussion] 100 Numpy exercises complete !

2016-07-15 Thread Nicolas P. Rougier
Hi all, It's my great pleasure to announce that "100 Numpy exercises" is now complete. I've also made a notebook out of them such that you can now test them on binder. https://github.com/rougier/numpy-100 If you spot errors or have better solutions to propose, PR welcome. (I'm still fighting

[Numpy-discussion] 100 numpy exercises (80/100)

2016-03-08 Thread Nicolas P. Rougier
Hi all, I've just added some exercises to the collection at https://github.com/rougier/numpy-100 (and in the process, I've discovered np.argpartition... nice!) If you have some ideas/comments/corrections... Still 20 to go... Nicolas ___ NumPy-Disc

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. R

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

2015-12-30 Thread Nicolas P. Rougier
gt;> 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. Rougier > wrote: > > Yes, it is the expected result. Thanks. > Maybe the set(a) & set(b) can

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

2015-12-30 Thread Nicolas P. Rougier
ices #indices of b where the elements of a in b occur > array([1, 2, 5, 7], dtype=int64) > > -Mark > > > On Wed, Dec 30, 2015 at 6:45 AM, Nicolas P. Rougier > wrote: > > I’m scratching my head around a small problem but I can’t find a vectorized > solution. >

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. >>

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

2015-12-30 Thread Nicolas P. Rougier
t; >>> 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 > wrote: > > I’m scratching my head around a small problem but I can’t find a vectorized &

[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

Re: [Numpy-discussion] Dynamic array list implementation

2015-12-23 Thread Nicolas P. Rougier
Typed list in numpy would be a nice addition indeed and your cython implementation is nice (and small). In my case I need to ensure a contiguous storage to allow easy upload onto the GPU. But my implementation is quite slow, especially when you add one item at a time: >>> python benchmark.py P

Re: [Numpy-discussion] Dynamic array list implementation

2015-12-22 Thread Nicolas P. Rougier
Yes, you can append/insert/remove items. It works pretty much like a python list in fact (but with a single data type for all elements). Nicolas > On 22 Dec 2015, at 20:19, Chris Barker wrote: > > sorry for being so lazy as to not go look at the project pages, but > > This sounds like it

[Numpy-discussion] Dynamic array list implementation

2015-12-22 Thread Nicolas P. Rougier
I've coded a typed dynamic list based on numpy array (needed for the glumpy project). Code is available from https://github.com/rougier/numpy-list A Numpy array list is a strongly typed list whose type can be anything that can be interpreted as a numpy data type. >>> L = ArrayList( [[0], [1,2

[Numpy-discussion] Numpy 100 exercices

2015-08-16 Thread Nicolas P. Rougier
Hi all, I've just updated the collection of numpy exercices (collected from this list and stack overflow) that lives at: https://github.com/rougier/numpy-100 http://www.labri.fr/perso/nrougier/teaching/numpy.100/index.html Unfortunately, I also realized there are currently "only" 60 exercices

[Numpy-discussion] EuroScipy 2015: Extended deadline (15/05/2015)

2015-05-01 Thread Nicolas P. Rougier
Extended deadline: 15th May 2015 EuroScipy 2015, the annual conference on Python in science will take place in Cambridge, UK on 26-30 August 2015. The conference features two days of tutorials followed by two days of scientific talk

[Numpy-discussion] EuroScipy 2015: Submission deadline in 3 days !!!

2015-04-27 Thread Nicolas P. Rougier
- Submission deadline in 3 days !!! - EuroScipy 2015, the annual conference on Python in science will take place in Cambridge, UK on 26-30 August 2015. The conference features two days of tutorials followed by two days of scientific t

[Numpy-discussion] EuroScipy 2015 : Call for talks, posters and tutorials [Reminder]

2015-04-17 Thread Nicolas P. Rougier
[Apology for cross-posting] Dear all, EuroScipy 2015, the annual conference on Python in science will take place in Cambridge, UK on 26-30 August 2015. The conference features two days of tutorials followed by two days of scientific talks & posters and an extra day dedicated to developer spri

[Numpy-discussion] EuroScipy 2015: Call for talks, posters & tutorials

2015-03-24 Thread Nicolas P. Rougier
Dear all, EuroScipy 2015, the annual conference on Python in science will take place in Cambridge, UK on 26-30 August 2015. The conference features two days of tutorials followed by two days of scientific talks & posters and an extra day dedicated to developer sprints. It is the major event in

Re: [Numpy-discussion] Bilinear interpolation (numpy only)

2014-12-14 Thread Nicolas P. Rougier
colas > On 14 Dec 2014, at 09:03, Jerome Kieffer wrote: > > On Sat, 13 Dec 2014 16:53:06 +0100 > "Nicolas P. Rougier" wrote: > >> >> Hi all, >> >> Does anyone has a simple 2D linear interpolation for resizing an image >> (without

[Numpy-discussion] Bilinear interpolation (numpy only)

2014-12-13 Thread Nicolas P. Rougier
Hi all, Does anyone has a simple 2D linear interpolation for resizing an image (without scipy) ? Ideally, something like ```def zoom(Z, ratio): ...``` where Z is a 2D scalar array and ratio the scaling factor. (I'm currently using ```scipy.ndimage.interpolation.zoom``` but I would like to avo

[Numpy-discussion] np.unique with structured arrays

2014-08-22 Thread Nicolas P. Rougier
Hello, I've found a strange behavior or I'm missing something obvious (or np.unique is not supposed to work with structured arrays). I'm trying to extract unique values from a simple structured array but it does not seem to work as expected. Here is a minimal script showing the problem: impor

Re: [Numpy-discussion] Inverted indices

2014-08-07 Thread Nicolas P. Rougier
Nicolas On 07 Aug 2014, at 14:04, Gregor Thalhammer wrote: > > Am 07.08.2014 um 13:59 schrieb Gregor Thalhammer > : > >> >> Am 07.08.2014 um 13:16 schrieb Nicolas P. Rougier : >> >>> >>> Hi, >>> >>> I've a small prob

Re: [Numpy-discussion] Inverted indices

2014-08-07 Thread Nicolas P. Rougier
Nice ! Thanks Stéfan. I will add it to the numpy 100 problems. Nicolas On 07 Aug 2014, at 13:31, Stéfan van der Walt wrote: > Hi Nicolas > > On Thu, Aug 7, 2014 at 1:16 PM, Nicolas P. Rougier > wrote: >> Here is a small example: >> >> Z = [(0,0), (1,1), (

[Numpy-discussion] Inverted indices

2014-08-07 Thread Nicolas P. Rougier
Hi, I've a small problem for which I cannot find a solution and I'm quite sure there is an obvious one: I've an array Z (any dtype) with some data. I've a (sorted) array I (of integer, same size as Z) that tells me the index of Z[i] (if necessary, the index can be stored in Z). Now, I have

Re: [Numpy-discussion] Find n closest values

2014-06-22 Thread Nicolas P. Rougier
vector graphics module in there would make it even better. Would > be nice if those projects could be merged. > I'm part of vispy actually, those are side experiments for this project. Nicolas > > On Sun, Jun 22, 2014 at 9:51 PM, Nicolas P. Rougier > wrote: > >

Re: [Numpy-discussion] Find n closest values

2014-06-22 Thread Nicolas P. Rougier
rk to do what you want to do. > > > On Sun, Jun 22, 2014 at 8:30 PM, Nicolas P. Rougier > wrote: > > Thanks, I'll try your solution. > > Data (L) is not so big actually, it represents pixels on screen and (I) > represents line position (for grid

Re: [Numpy-discussion] Find n closest values

2014-06-22 Thread Nicolas P. Rougier
ay. Note that the > output isn't 100% identical; youd need to do a little tinkering to figure out > the correct/desired rounding behavior. > > > On Sun, Jun 22, 2014 at 5:16 PM, Nicolas P. Rougier > wrote: > > Thanks for the answer. > I was secretly hop

[Numpy-discussion] 100 numpy exercises, now in Julia

2014-06-22 Thread Nicolas P. Rougier
Hi all, Michiaki Ariga has started conversion of 100 numpy exercises in Julia. I know this might be a bit off-topic but I thought it was interesting enough. Github repository is at https://github.com/chezou/julia-100-exercises Nicolas ___ NumPy-Disc

Re: [Numpy-discussion] Find n closest values

2014-06-22 Thread Nicolas P. Rougier
ity is fine, and everything is vectorized, so I doubt you will get > huge gains. > > You could take a look at the functions in scipy.spatial, and see how they > perform for your problem parameters. > > > On Sun, Jun 22, 2014 at 10:22 AM, Nicolas P. Rougier > wrote: >

[Numpy-discussion] Find n closest values

2014-06-22 Thread Nicolas P. Rougier
Hi, I have an array L with regular spaced values between 0 and width. I have a (sorted) array I with irregular spaced values between 0 and width. I would like to find the closest value in I for any value in L. Currently, I'm using the following script but I wonder if I missed an obvious (and

Re: [Numpy-discussion] 100 Numpy exercices

2014-05-29 Thread Nicolas P. Rougier
How would you do that ? 5. Create a vector with values ranging from 10 to 99 9. Create a 5x5 matrix with values 1,2,3,4 just below the diagonal On 29 May 2014, at 07:04, nicky van foreest wrote: > Hi, > > Very helpful, these exercises. > > Pertaining to exercise 9. Is there a reason not t

Re: [Numpy-discussion] 100 Numpy exercices

2014-05-29 Thread Nicolas P. Rougier
Hi Valentin, Thanks for reminded me about this great tool. I intended to use it after I get all 100 exercises but it really helps track errors quickly. I will now use it to keep a notebook up to date with each commit . Nicolas On 28 May 2014, at 23:46, Valentin Haenel wrote: > Hi Nicolas,