Hi,
I'm not sure if this is a stupid question or not.
Let's say I have 3 arrays of numpy, A1, A2, A3 and 3 floats, c1, c2, c3
and I would like to evaluate B = A1 * c1 + A2 * c2 + A3 * c3
will numpy calculate this for example
E1 = A1*c1 E2 = A2*c2 E3 = A3*c3 D1 = E1+E2 B = D1+E3
or is he smarter? In C ++, I had a neat way to abstract this operation.
I have defined a number of common LC, LC template functions for a linear combination, such as:
template<class T,class D> void LC( T & R, T & L0,D C0, T & L1,D C1, T & L2,D C2) { R = L0*C0 +L1*C1 +L2*C2; }
and then specializes for different types,
for example, for an array, the code looked like
for (int i=0; i<L0.length; i++) R.array[i] = L0.array[i]*C0 + L1.array[i]*C1 + L2.array[i]*C2;
which avoids creating new intermediate arrays.
This may seem messy, but it works very well.
I could do something similar in python, but I'm not sure if its nescesary.
Thanks in advance for your understanding. -nick