mljs / matrix

Matrix manipulation and computation library
https://mljs.github.io/matrix/
MIT License
353 stars 54 forks source link

sum over row or column #99

Closed thegodone closed 4 years ago

thegodone commented 4 years ago

How to sum per row or column ?

targos commented 4 years ago

matrix.sum('row') or matrix.sum('column'). All methods are documented here: https://mljs.github.io/matrix/classes/matrix.html

lpatiny commented 4 years ago

Full example:

const { Matrix } = require('ml-matrix');

let matrix = new Matrix([
  [1, 2],
  [3, 4]
]);

let sunColumn = matrix.sum('column');
console.log(sunColumn);

let sunRow = matrix.sum('row');
console.log(sunRow);