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

Ruben Salvador rsalvador.wk@gmail....
Wed Sep 9 05:28:29 CDT 2009


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 array of 'a' with each scalar of 'b' for all rows).
It's straight forward doing the sum with a for loop (yes, I learnt C long
ago :S ):

for i in range(8):
    c[i] = a[i] + b[i]

but, is there a Pythonic way to do this? or even better...which is the
pythonic way of doing it? because I'm sure there is one...

Thanks, and sorry for such an easy question...but I'm stuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090909/ac22715a/attachment.html 


More information about the NumPy-Discussion mailing list