Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-10 Thread Ruben Salvador
Well...you are right, sorry, I just thought 'np.shape(offspr)' result would be enough. Obviously, not! offspr wasn't actually a numpy array, but a Python list. I'm sorry for the inconvenience but I didn't realizeI'm just changing my code so that I just use numpy arrays, and forgot to change of

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-10 Thread Francesc Alted
A Thursday 10 September 2009 14:22:57 Dag Sverre Seljebotn escrigué: > > > (Also a guard in timeit against CPU frequency scaling errors would be > > > > > > great :-) Like simply outputting a warning if frequency scaling is > > > > > > detected). > > > > Sorry, I don't get this one. > > I had

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-10 Thread Dag Sverre Seljebotn
Francesc Alted wrote: > A Thursday 10 September 2009 13:45:10 Dag Sverre Seljebotn escrigué: > > Do you see any issues with this approach: Add a flag timeit to provide > > > two modes: > > > > > > a) Do an initial run which is always not included in timings (in fact, > > > as it gets "min"

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-10 Thread Francesc Alted
A Thursday 10 September 2009 13:45:10 Dag Sverre Seljebotn escrigué: > Francesc Alted wrote: > > A Wednesday 09 September 2009 20:17:20 Dag Sverre Seljebotn escrigué: > > > Ruben Salvador wrote: > > > > Your results are what I expected...but. This code is called from my > > > > main > > > > > >

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-10 Thread Dag Sverre Seljebotn
Francesc Alted wrote: > A Wednesday 09 September 2009 20:17:20 Dag Sverre Seljebotn escrigué: > > > Ruben Salvador wrote: > > > > Your results are what I expected...but. This code is called from my > main > > > > program, and what I have in there (output array already created for > both >

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-10 Thread Francesc Alted
A Thursday 10 September 2009 11:43:44 Ruben Salvador escrigué: > OK. Thanks everybody :D > But...what is happening now? When executing this code: > > print ' . object parameters mutation .' > print 'np.shape(offspr)', np.shape(offspr) > print 'np.shape(offspr[0])', np.shape(offspr[0]) > pr

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-10 Thread Ruben Salvador
OK. Thanks everybody :D But...what is happening now? When executing this code: print ' . object parameters mutation .' print 'np.shape(offspr)', np.shape(offspr) print 'np.shape(offspr[0])', np.shape(offspr[0]) print "np.shape(r)", np.shape(r) print "np.shape(offspr_sigma)", np.shape(offs

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-10 Thread Ruben Salvador
OK. I get the idea, but I can't see it. In both cases, as the print statement shows, offspr is already created. I need light :S On Wed, Sep 9, 2009 at 8:17 PM, Dag Sverre Seljebotn < da...@student.matnat.uio.no> wrote: > Ruben Salvador wrote: > > Your results are what I expected...but. This code

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-10 Thread Francesc Alted
A Wednesday 09 September 2009 20:17:20 Dag Sverre Seljebotn escrigué: > Ruben Salvador wrote: > > Your results are what I expected...but. This code is called from my main > > program, and what I have in there (output array already created for both > > cases) is: > > > > print "lambd", lambd > > pri

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-10 Thread Citi, Luca
Hi Ruben, > In both cases, as the print > statement shows, offspr is already created. >>> offspr[...] = r + a[:, None] means "fill the existing object pointed by offspr with r + a[:, None]" while >>> offspr = r + a[:,None] means "create a new array and assign it to the variable offspr (after dec

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-09 Thread Dag Sverre Seljebotn
Ruben Salvador wrote: > Your results are what I expected...but. This code is called from my main > program, and what I have in there (output array already created for both > cases) is: > > print "lambd", lambd > print "np.shape(a)", np.shape(a) > print "np.shape(r)", np.shape(r) > print "np.shap

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-09 Thread Ruben Salvador
I forgot...just in case: rsalva...@cactus:~$ python --version Python 2.5.2 python-scipy: version 0.6.0 On Wed, Sep 9, 2009 at 2:36 PM, Ruben Salvador wrote: > Your results are what I expected...but. This code is called from my main > program, and what I have in there (output array already crea

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-09 Thread Ruben Salvador
Your results are what I expected...but. This code is called from my main program, and what I have in there (output array already created for both cases) is: print "lambd", lambd print "np.shape(a)", np.shape(a) print "np.shape(r)", np.shape(r) print "np.shape(offspr)", np.shape(offspr) t = clock()

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-09 Thread Citi, Luca
I am sorry but it doesn't make much sense. How do you measure the performance? Are you sure you include the creation of the "c" output array in the time spent (which is outside the for loop but should be considered anyway)? Here are my results... In [84]: a = np.random.rand(8,26) In [85]: b = n

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-09 Thread Pauli Virtanen
Wed, 09 Sep 2009 13:08:22 +0200, Ruben Salvador wrote: > Perfect! Thank you very much :D > > It's not obvious, though...I think I should read more deeply into > Python/NumPy...but for the use I'm giving to it... > > Anyway, I thought the pythonic way would be faster, but after trying > with a siz

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-09 Thread Ruben Salvador
Perfect! Thank you very much :D It's not obvious, though...I think I should read more deeply into Python/NumPy...but for the use I'm giving to it... Anyway, I thought the pythonic way would be faster, but after trying with a size 8 instead of 8...the for loop is faster! Pythonic time ==> 0.3

Re: [Numpy-discussion] Adding a 2D with a 1D array...

2009-09-09 Thread Citi, Luca
Hi Ruben One dimensional arrays can be thought of as rows. If you want a column, you need to append a dimension. >>> d = a + b[:,None] which is equivalent to >>> d = a + b[:,np.newaxis] Best, Luca ___ NumPy-Discussion mailing list NumPy-Discussion@sc

[Numpy-discussion] Adding a 2D with a 1D array...

2009-09-09 Thread Ruben Salvador
Hi there! I'm sure I'm missing something, but I am not able of doing a simple sum of two arrays with different dimensions. I have a 2D array and a 1D array np.shape(a) (8, 26) np.shape(b) (8,) and I want to sum each *row* of 'a' with the equivalent *row* of 'b' (this is, summing each 1D row arra