matrixSumColumns function

Array matrixSumColumns(
  1. Array2d a
)

Sum the all columns of the array

Examples

var a = Array2d([
  Array([1, 1, 1]),
  Array([1, 1, 1]),
  Array([1, 1, 1])
]);

print(matrixSumColumns(a));

/* output:
Array([3, 3, 3])
*/

Implementation

Array matrixSumColumns(Array2d a) {
  a.isMatrix();

  var aRows = a.length;
  var aColumns = a[0].length;

  var c = Array.fixed(aColumns, initialValue: 0.0);

  for (var j = 0; j < aColumns; j++) {
    // bColumn
    for (var i = 0; i < aRows; i++) {
      //
      c[j] += a[i][j];
    }
  }

  return c;
}