The Matrix class provides static methods for operations between two matrices and instance methods for matrix multiplication.
Static Operations:
Matrix.add(A, B): AdditionMatrix.sub(A, B): SubtractionMatrix.mul(A, number): Scalar multiplicationMatrix.div(A, number): Scalar divisionMatrix.mod(B, number): ModuloMatrix.max(A, B): Element-wise maximumMatrix.min(A, B): Element-wise minimum
Instance Operations:
A.mmul(B): Matrix multiplication (dot product)
const { Matrix } = require('ml-matrix');
var A = new Matrix([[1, 1], [2, 2]]);
var B = new Matrix([[3, 3], [1, 1]]);
const addition = Matrix.add(A, B); // Matrix [[4, 4], [3, 3]]
const subtraction = Matrix.sub(A, B); // Matrix [[-2, -2], [1, 1]]
const multiplication = A.mmul(B); // Matrix [[4, 4], [8, 8]]
const mulByNumber = Matrix.mul(A, 10); // Matrix [[10, 10], [20, 20]]
const divByNumber = Matrix.div(A, 10); // Matrix [[0.1, 0.1], [0.2, 0.2]]
const modulo = Matrix.mod(B, 2); // Matrix [[1, 1], [1, 1]]
const maxMatrix = Matrix.max(A, B); // Matrix [[3, 3], [2, 2]]
const minMatrix = Matrix.min(A, B); // Matrix [[1, 1], [1, 1]]