arr: The Original 2D array data.
Get the original array.
Get the size of Matrix, including rows and columns.
The sum of data in the same row/column
axis: If axis is set to 1, the sum of all the data of the same row is calculated, otherwise the column is computed. Default to 1.
The minimum value of data in the same row/column.
axis: If axis is set to 1, the minimum value of all data in the same row is calculated, otherwise the column is computed. default to 0.
The maximum value of data in the same row/column.
axis: If axis is set to 1, the maximum value of all data in the same row is calculated, otherwise the column is computed. default to 0.
The average value of the same row/column of data
arr: dataset to calculate. axis: If axis is set to 1, the average value of all the data in the same row is calculated, otherwise the column is computed
Transpose the Matrix.
If there are two parameters, the zero matrix of the specified size is returned. If there is only one parameter, the one dimensional array is returned
Be similar with zeros().
Matrix subtraction.
toSub: Matrix to sub with.
Matrix addition.
toAdd: Matrix to add with.
Matrix multiplication.
toMult: Matrix to multiply with.
Matrix Division.
toDivide: Matrix to divide with.
const Matrix = require('mlhelper').utils.Matrix;
const dataSet = [
[2,4,6],
[5,7,1],
[3,3,1]
];
const dataSet2 = [
[1,3,5],
[2,4,7],
[3,5,8]
];
let matA = new Matrix(dataSet),
matB = new Matrix(dataSet2);
let result = matA.add(matB);
expect(result.toArray()).to.eql([
[3,7,11],
[7,11,8],
[6,8,9]
]); // true;
expect(matA.max(1)).to.eql([6,7,3]); //true
expect(matA.max(0)).to.eql([5,7,6]); //true
expect(matA.transpose()).to.eql([[2,5,3],[4,7,3],[6,1,1]]); //true
expect(Matrix.ones(2,2)).to.eql([[1,1],[1,1]]); //true
expect(Matrix.ones(2,2)).to.eql([[1,1],[1,1]]); //true