title: Vector (array) addition in Postgres
body: <p>I have a column with <code>numeric[]</code> values which all have the same size. I'd like to take their element-wise average. By this I mean that the average of</p>
  
  <pre><code>{1, 2, 3}, {-1, -2, -3}, and {3, 3, 3}
  </code></pre>
  
  <p>should be <code>{1, 1, 1}</code>. Also of interest is how to sum these element-wise, although I expect that any solution for one will be a solution for the other.</p>
  
  <p>(NB: The length of the arrays is fixed within a single table, but may vary between tables. So I need a solution which doesn't assume a certain length.)</p>
  
  <p>My initial guess is that I should be using <code>unnest</code> somehow, since <code>unnest</code> applied to a <code>numeric[]</code> column flattens out all the arrays. So I'd like to think that there's a nice way to use this with some sort of windowing function + <code>group by</code> to pick out the individual components of each array and sum them.</p>
  
  <pre><code>-- EXAMPLE DATA
  CREATE TABLE A
    (vector numeric[])
  ;
  
  INSERT INTO A
    VALUES
      ('{1, 2, 3}'::numeric[])
      ,('{-1, -2, -3}'::numeric[])
      ,('{3, 3, 3}'::numeric[])
  ;
  </code></pre>