title: Sum columns of a 2D array
body: <p>I have an <code>IEnumerable&lt;IEnumerable&lt;double&gt;&gt;</code> which can basically be thought of as a 2D array of doubles and what I want to do is get a 1D array (or list or whatever) that is the total for all the columns of my original collection. In other words, if I had:</p>
  
  <pre><code>1   2   3   4
  2   3   1   6
  3   4   5   6
  -------------
  6   9   9   16
  </code></pre>
  
  <p>I'd want the last line (which is not part of the original collection, obviously). </p>
  
  <p>Is there a simple way to do this with LINQ so that I don't have to loop over the whole thing? I know I can use <code>.Sum</code> to total one row or one column, but I want to total each row.</p>
  
  <p>I've seen some other questions (mostly dealing with database queries) that suggest using <code>group</code> but that didn't seem to work for me. I tried this:</p>
  
  <pre><code>            var totals = from p in toTotal
                           group p by 1 into g
                           select g.Sum(t =&gt; t.First()); 
  </code></pre>
  
  <p>But that just totals everything.</p>
  
  <p>Is there a clever way to do this?</p>
  
  <p>Edit: for example, if <code>toTotal</code> was defined as:</p>
  
  <pre><code>    List&lt;List&lt;double&gt;&gt; toTotal = new List&lt;List&lt;double&gt;&gt;() {
          new List&lt;double&gt; {1,   2,   3,   4},
          new List&lt;double&gt; {2,   3 ,  1,   6},
          new List&lt;double&gt; {3 ,  4,   5 ,  6}
      };
  </code></pre>