Hey guys,

I am quite a beginner at using Julia and this is my first post, so apologies if there is an obvious answer! I would like to find out if there is an easy way to perform the sumproduct excel function in Julia.

As an example, I currently have the following vectors:

vec_1 = [a,b,c]

vec_2 = [e,f,g]

I would like to end up with a vector containing:

vec_3 = [a*e, (a*e) + (b*f), (a*e) + (b*f) + (c*g)]

I would be able to do this manually, but am quite interested if there is a streamlined way

Thanks.

~~This is an inner product (a dot product). ~~`vec_1' * vec_2`

(or just `vec_1'vec_2`

) will do what you want. Sorry, I misread your question; this is `cumsum(vec_1 .* vec_2)`

.

(Technically, if your vectors are complex numbers, then `vec_1' * vec_2`

will also conjugate the elements of `vec_1`

in the product. If you needed an â€śunconjugatedâ€ť dot product for complex vectors, you could do `transpose(vec_2) * vec_2`

.)

1 Like

That only gives the last element though. Maybe something like

```
julia> a, b, c, e, f, g = 1:6;
julia> vec_1 = [a,b,c];
julia> vec_2 = [e,f,g];
julia> cumsum(x*y for (x,y) in zip(vec_1, vec_2))
3-element Array{Int64,1}:
4
14
32
```

2 Likes

The intermediate allocation of `vec_1 .* vec_2`

I guess.

2 Likes

Probably a premature optimization for someone porting from Excelâ€¦

1 Like

Thanks for the quick responses guys, the cumsum(vec_1.*vec_2) was exactly what I was after.

Happy Friday!