[Numpy-discussion] Fast vector multiplication
Vicent Mas (V+)
vmas at carabos.com
Sat Jan 20 03:13:36 CST 2007
El Friday, 19 de January de 2007 23:40 Mark Janikas escribió:
> Hello all,
>
>
>
> I am trying to figure out the most efficient way to get the sum of
> the product of two vectors where id != id.
>
>
>
> E.g.:
>
>
>
> X = array([1,2,3])
>
> Y = array([1,2,3])
>
>
>
> Z = (1*2) + (1*3) + (2*1) + (2*3) + (3*1) + (3*2) = 22
>
>
>
> I could obviously do this with loops, but I was wondering if there is
> a version of multiply that could be used... or a form of vectorize.
> Any ideas would be greatly appreciated.
>
>
What about this?
In [64]: a = numpy.array([1,2,3])
In [65]: b = numpy.array([4,5,6]).reshape(3,1)
In [66]: numpy.multiply(a, b).sum() - numpy.dot(a, b).sum()
Out[66]: 58
Hope it helps.
--
::
\ / Vicent Mas http://www.carabos.com
0;0
/ \ Cárabos Coop. Enjoy Data
V V
" "
More information about the Numpy-discussion
mailing list