$ npm install node-matrix
var m1 =;var m2 =;Matrix; // [ [1, 3, 6], [8, 5, 0] ]
Create a new instance of Matrix. You can pass in a multidimensional array:
var matrix =;
Or you can pass in an object specifying the dimensions and default values. If you don't pass in a default value, or a function to be executed for each element to calculate it's value, then it will set the value of each element to 0.
var matrix = ; // Set the value of each element to 0var matrix = ; // // Set the value of each element to 5var matrix = ; // Set the value of each element to a random number
You can access the matrix's values the same way you can access them from an array:
0 corresponding to the row number and
1 corresponding to the column number. You also now have access to
matrix.dimensions, which will return an array where the first element is the number of rows in the matrix, and the second element is the number of columns in the matrix.
Matrix; // matrix multiplication
Matrix; // scalar multiplication
Matrix; // element-wise multiplication
matrix; // subtract two from each element in the matrix