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

Ruben Salvador rsalvador.wk at gmail.com
Wed Sep 9 07:08:22 EDT 2009


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 80000 instead of 8...the for loop is faster!

Pythonic time ==> 0.36776400 seconds
For loop time ==> 0.31708717 seconds

:S

On Wed, Sep 9, 2009 at 12:46 PM, Citi, Luca <lciti at essex.ac.uk> wrote:

> 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 at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090909/5d653743/attachment.html>


More information about the NumPy-Discussion mailing list