# node-matrix

> A tiny matrix library

Latest version **1.0.0** (published 2017-11-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-matrix
pnpm add node-matrix
yarn add node-matrix
bun add node-matrix
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2017-11-18 |
| First published | 2015-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Steven Miller |
| Maintainers | stevenmiller888 |

## Links

- npm: https://www.npmjs.com/package/node-matrix
- Repository: https://github.com/stevenmiller888/matrix
- Homepage: https://github.com/stevenmiller888/matrix#readme
- Issues: https://github.com/stevenmiller888/matrix/issues
- npm.io page: https://npm.io/package/node-matrix

## Recent versions

- 1.0.0 (latest) — 2017-11-18
- 0.1.1 — 2015-07-24
- 0.1.0 — 2015-07-07
- 0.0.6 — 2015-07-05
- 0.0.5 — 2015-06-25
- 0.0.4 — 2015-06-24
- 0.0.3 — 2015-06-22
- 0.0.2 — 2015-06-22
- 0.0.1 — 2015-06-21

## README

# matrix
[![NPM version][npm-image]][npm-url]
[![build status][circle-image]][circle-url]
[![license][license-image]][license-url]

> A tiny matrix library written in JavaScript

## Installation

```bash
$ npm install node-matrix
```

## Example

```js
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:

```js
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.

```js
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()

```js
Matrix.add(m1, m2);
```

### Matrix.subtract()

```js
Matrix.subtract(m1, m2);
```

### Matrix.multiply()

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

### Matrix.multiplyScalar()

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

### Matrix.multiplyElements()

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

### matrix.transpose()

```js
matrix.transpose();
```

### matrix.transform()

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

## License

[MIT](https://tldrlegal.com/license/mit-license)

[npm-image]: https://img.shields.io/npm/v/node-matrix.svg?style=flat-square
[npm-url]: https://npmjs.org/package/node-matrix
[circle-image]: https://img.shields.io/circleci/project/stevenmiller888/matrix.svg
[circle-url]: https://circleci.com/gh/stevenmiller888/matrix
[license-image]: https://img.shields.io/npm/l/express.svg
[license-url]: https://tldrlegal.com/license/mit-license

---
_Source: https://npm.io/package/node-matrix · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
