title: dot product of vector < vector < int > > over the first dimension
body: <p>I have</p>
  
  <pre><code>vector &lt; vector &lt; int &gt; &gt; data_mat ( 3, vector &lt; int &gt; (4) );
  vector          &lt; int &gt;   data_vec ( 3                     ); 
  </code></pre>
  
  <p>where <code>data_mat</code> can be thought of as a matrix and <code>data_vec</code> as a column vector, and I'm looking for a way to compute the inner product of every column of <code>data_mat</code> with <code>data_vec</code>, and store it in another <code>vector &lt; int &gt; data_out (4)</code>.</p>
  
  <p>The example <a href="http://liveworkspace.org/code/2bW3X5%241" rel="nofollow">http://liveworkspace.org/code/2bW3X5%241</a> using <code>for_each</code> and <code>transform</code>, can be used to compute column sums of a matrix:</p>
  
  <pre><code>sum=vector&lt;int&gt; (data_mat[0].size());
  for_each(data_mat.begin(), data_mat.end(),
           [&amp;](const std::vector&lt;int&gt;&amp; c) {
              std::transform(c.begin(), c.end(), sum.begin(), sum.begin(),
                             [](int d1, double d2) 
                               { return d1 + d2; }
                            );
              }
          );
  </code></pre>
  
  <p>Is it possible, in a similar way (or in a slightly different way that uses STL functions), to compute column dot products of matrix columns with a vector?</p>
  
  <p>The problem is that the 'd2 = d1 + d2' trick does not work here in the column inner product case -- if there is a way to include a d3 as well that would solve it ( d3 = d3 + d1 * d2 ) but ternary functions do not seem to exist in <code>transform</code>.</p>