title: linear combinations in python/numpy
body: <p>greetings,</p>
  
  <p>I'm not sure if this is a dumb question or not.</p>
  
  <p>Lets say I have 3 numpy arrays, A1,A2,A3, and 3 floats, c1,c2,c3</p>
  
  <p>and I'd like to evaluate B = A1*c1+ A2*c2+ A3*c3</p>
  
  <p>will numpy compute this as for example,</p>
  
  <pre><code> E1 = A1*c1
   E2 = A2*c2
   E3 = A3*c3
   D1 = E1+E2
   B = D1+E3
  </code></pre>
  
  <p>or is it more clever than that? In c++ I had a neat way to abstract this kind of operation.</p>
  
  <p>I defined series of general 'LC' template functions, LC for linear combination like:</p>
  
  <pre><code>template&lt;class T,class D&gt;
  void LC( T &amp; R,
      T &amp; L0,D C0,
      T &amp; L1,D C1,
      T &amp; L2,D C2)
  {
      R = L0*C0
          +L1*C1
          +L2*C2;        
  }
  </code></pre>
  
  <p>and then specialized this for various types, </p>
  
  <p>so for instance, for an array the code looked like</p>
  
  <pre><code>for (int i=0; i&lt;L0.length; i++)
      R.array[i] =
      L0.array[i]*C0 +
      L1.array[i]*C1 +
      L2.array[i]*C2;
  </code></pre>
  
  <p>thus avoiding having to create new intermediate arrays.</p>
  
  <p>This may look messy but it worked really well.</p>
  
  <p>I could do something similar in python, but I'm not sure if its nescesary.</p>
  
  <p>Thanks in advance for any insight.
  -nick</p>