New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

node-matrix

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-matrix

A tiny matrix library

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

matrix

NPM version build status license

A tiny matrix library written in JavaScript

Installation

$ npm install node-matrix

Example

var m1 = Matrix([
  [1, 3, 1],
  [1, 0, 0]
]);

var m2 = Matrix([
  [0, 0, 5],
  [7, 5, 0]
]);

Matrix.add(m1, m2); // [ [1, 3, 6], [8, 5, 0] ]

API

Matrix()

Create a new instance of Matrix. You can pass in a multidimensional array:

var matrix = Matrix([
  [4, 1, 9],
  [3, 8, 2]
]);

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 = Matrix({ rows: 3, columns: 2 }); // Set the value of each element to 0
var matrix = Matrix({ rows: 3, columns: 2, values: 5 });  // // Set the value of each element to 5
var matrix = Matrix({ rows: 3, columns: 2, values: Math.random }); // 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: matrix[0][1], with 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.add()

Matrix.add(m1, m2);

Matrix.subtract()

Matrix.subtract(m1, m2);

Matrix.multiply()

Matrix.multiply(m1, m2);  // matrix multiplication

Matrix.multiplyScalar()

Matrix.multiplyScalar(m1, 4); // scalar multiplication

Matrix.multiplyElements()

Matrix.multiplyElements(m1, m2); // element-wise multiplication

matrix.transpose()

matrix.transpose();

matrix.transform()

matrix.transform(function(num) { return num - 2 });   // subtract two from each element in the matrix

License

MIT

FAQs

Package last updated on 18 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts