npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

matrix-sync

v6.15.0

Published

Dense matrix algebra for JavaScript and TypeScript

Readme

matrix-sync

Dense matrix algebra for JavaScript and TypeScript.

Create matrices, run element-wise math, multiply, invert, and factorize — in Node.js and the browser.

| | | | --- | --- | | npm | matrix-sync | | repo | sync-package/matrix | | docs | API reference | | license | MIT | | author | browndev88 · [email protected] |

ci types license npm


Contents

  1. Install
  2. Quick start
  3. What it covers
  4. Build a matrix
  5. Arithmetic
  6. Shape and stats
  7. Linear algebra
  8. Module formats
  9. License

Install

npm install matrix-sync

Requires a current Node.js release. Type definitions ship in the package (matrix.d.ts).


Quick start

import { Matrix, inverse, solve, QrDecomposition } from 'matrix-sync';

const A = new Matrix([
  [2, 3, 5],
  [4, 1, 6],
  [1, 3, 0],
]);

A.mmul(inverse(A)); // ~ identity

What it covers

| Area | API | | --- | --- | | Storage | Matrix, SymmetricMatrix, DistanceMatrix, 1D/2D wrappers | | Construction | zeros, ones, eye, rand, diag, columnVector, rowVector | | Arithmetic | add sub mul div mod max min — static or in-place | | Products | mmul, mmulByTranspose, transposeMultiply, kronecker, gram | | Element math | abs, exp, log, sqrt, sin, cos, … (same set as Math) | | Structure | transpose, concat, diag, set / get, row & column views | | Reductions | sum, mean, prod, norm, applyAlongAxis | | Factorizations | SVD, EVD, QR, LU, Cholesky, NIPALS | | Solvers | inverse, pseudoInverse, solve, linearDependencies | | Stats | covariance, correlation |


Build a matrix

import { Matrix } from 'matrix-sync';

const fromRows = new Matrix([
  [1, 2],
  [3, 4],
]);

Matrix.zeros(3, 2); // 3×2 zeros
Matrix.ones(2, 3);  // 2×3 ones
Matrix.eye(3, 4);   // 3×4 identity-padded
Matrix.columnVector([5, 6]);

Join along a dimension. Operands are not mutated. Row concat needs matching columns; column concat needs matching rows.

fromRows.concat([[5, 6]]);
fromRows.concat(Matrix.columnVector([5, 6]), 'column');

Arithmetic

Static (returns a new matrix):

Matrix.add(A, B);
Matrix.sub(A, B);
A.mmul(B);          // matrix product
Matrix.mul(A, 10);  // scale
Matrix.div(A, 10);
Matrix.mod(B, 2);
Matrix.max(A, B);
Matrix.min(A, B);

In-place (mutates the receiver):

C.add(A);
C.sub(A);
C.mul(10);
C.div(10);
C.mod(2);

Element-wise mathMatrix.exp(A), Matrix.cos(A), Matrix.abs(A), or A.abs() in place.

abs acos acosh asin asinh atan atanh cbrt ceil clz32 cos cosh exp expm1 floor fround log log1p log10 log2 round sign sin sinh sqrt tan tanh trunc


Shape and stats

A.rows;
A.columns;
A.size;
A.get(0, 0);
A.set(1, 0, 10);
A.isSquare();
A.isSymmetric();
A.diag();
A.mean();
A.prod();
A.norm();           // Frobenius
A.transpose();

Reduce along an axis with any callback. The callback receives a plain array and its index.

const M = new Matrix([
  [1, 2, 3],
  [4, 5, 6],
]);

const sum = (vector) => vector.reduce((n, x) => n + x, 0);

M.applyAlongAxis(sum, 'row');    // [6, 15]
M.applyAlongAxis(sum, 'column'); // [5, 7, 9]

Linear algebra

import {
  Matrix,
  inverse,
  solve,
  linearDependencies,
  QrDecomposition,
  LuDecomposition,
  CholeskyDecomposition,
  EigenvalueDecomposition,
} from 'matrix-sync';

Inverse

const A = new Matrix([
  [2, 3, 5],
  [4, 1, 6],
  [1, 3, 0],
]);

inverse(A);
A.mmul(inverse(A)); // ~ I

// Singular / rank-deficient: SVD-based inverse
const S = new Matrix([
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
]);
inverse(S, true);

Pseudo-inverse

const A = new Matrix([
  [1, 2],
  [3, 4],
  [5, 6],
]);

const Ap = A.pseudoInverse();
A.mmul(Ap).mmul(A); // ~ A

Least squares

Solve A x = B.

const A = new Matrix([
  [3, 1],
  [4.25, 1],
  [5.5, 1],
  [8, 1],
]);
const B = Matrix.columnVector([4.5, 4.25, 5.5, 5.5]);
const x = solve(A, B);
Matrix.sub(B, A.mmul(x)); // residual

Pass true as the third argument to solve to use SVD when A is singular.

Factorizations

| Method | Class | Pieces | | --- | --- | --- | | QR | QrDecomposition | orthogonalMatrix, upperTriangularMatrix | | LU | LuDecomposition | lowerTriangularMatrix, upperTriangularMatrix, pivotPermutationVector | | Cholesky | CholeskyDecomposition | lowerTriangularMatrix | | EVD | EigenvalueDecomposition | realEigenvalues, imaginaryEigenvalues, eigenvectorMatrix |

const QR = new QrDecomposition(A);
QR.orthogonalMatrix;
QR.upperTriangularMatrix;

const LU = new LuDecomposition(A);
LU.lowerTriangularMatrix;
LU.upperTriangularMatrix;
LU.pivotPermutationVector; // e.g. [1, 2, 0]

const chol = new CholeskyDecomposition(A);
chol.lowerTriangularMatrix;

const evd = new EigenvalueDecomposition(A);
evd.realEigenvalues;
evd.imaginaryEigenvalues;
evd.eigenvectorMatrix;

Row dependencies

const A = new Matrix([
  [2, 0, 0, 1],
  [0, 1, 6, 0],
  [0, 3, 0, 1],
  [0, 0, 1, 0],
  [0, 1, 2, 0],
]);

linearDependencies(A);
// zero row → independent
// e.g. [0, 0, 0, 4, 1] → row 1 = 4 × row 3 + row 4

Module formats

| Environment | How | | --- | --- | | ESM | import { Matrix } from 'matrix-sync' | | CommonJS | const { Matrix } = require('matrix-sync') | | Browser (UMD) | matrix.umd.js — global matrixSync | | Types | matrix.d.ts included |

import { Matrix } from 'matrix-sync';
const ones = Matrix.ones(5, 5);
const { Matrix } = require('matrix-sync');
const ones = Matrix.ones(5, 5);

Full method list: API documentation.


License

MIT. See LICENSE.

Maintained by sync-package · browndev88 ([email protected]).