Sum of the product of three or more arrays

Hi All, Given three vectors of the same lengths, X, Y, and Z, I am looking for an efficient way to calculate the following: sum(x[i]*y[i]*z[i], for i=1..n ) I am not sure if there is a vectorized way to do this. Thanks, Geoffrey

I think I figured out: sum(X*Y*Z). Never mind. On 10/18/07, Geoffrey Zhu <zyzhu2000@gmail.com> wrote:
Hi All,
Given three vectors of the same lengths, X, Y, and Z, I am looking for an efficient way to calculate the following:
sum(x[i]*y[i]*z[i], for i=1..n )
I am not sure if there is a vectorized way to do this.
Thanks, Geoffrey

Geoffrey Zhu wrote:
Hi All,
Given three vectors of the same lengths, X, Y, and Z, I am looking for an efficient way to calculate the following:
sum(x[i]*y[i]*z[i], for i=1..n )
(x*y*z).sum() -- 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

On 10/18/07, Robert Kern <robert.kern@gmail.com> wrote:
Geoffrey Zhu wrote:
Hi All,
Given three vectors of the same lengths, X, Y, and Z, I am looking for an efficient way to calculate the following:
sum(x[i]*y[i]*z[i], for i=1..n )
(x*y*z).sum()
-- 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 Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Thanks Robert. (x*y*z).sum() is probably faster than sum(x*y*z).
participants (2)
-
Geoffrey Zhu
-
Robert Kern