[Numpy-discussion] array multiplication

Nadav Horesh nadavh@visionsense....
Thu Sep 17 00:39:52 CDT 2009




-----הודעה מקורית-----
מאת: numpy-discussion-bounces@scipy.org בשם Robert Kern
נשלח: ה 17-ספטמבר-09 00:40
אל: Discussion of Numerical Python
נושא: Re: [Numpy-discussion] array multiplication
2009/9/16 Ernest Adrogu? <eadrogue@gmx.net>:
> Hi,
> I have two 1-d arrays (a and b), and I want to create a
> third 2-d array, whose rows are of the form a[i]*b:
> c = np.zeros((len(a),b))
> c[0] = a[0]*b
> c[1] = a[1]*b
> .
> .
> .
> Is there an easy way to do this (e.g, without a loop)?

c = a[:,np.newaxis] * b


Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
NumPy-Discussion mailing list

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 3240 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090917/4065af9d/attachment.bin 

More information about the NumPy-Discussion mailing list