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-ops-core

v1.0.2

Published

Dense linear algebra for JavaScript and TypeScript

Readme

matrix-ops-core

Dense linear algebra for JavaScript and TypeScript. Create matrices, run element-wise and matrix products, factorize, invert, and solve linear systems — all in one package.

Works in Node.js and the browser (ESM, CommonJS, and UMD).

npm install matrix-ops-core
import { Matrix, SVD, inverse, solve } from 'matrix-ops-core';

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

X.mmul(inverse(X)); // ≈ I

Repository: github.com/Ops-Core/matrix


What you get

| Area | Highlights | | --- | --- | | Construction | new Matrix(...), zeros, ones, eye, diag, rand, row/column vectors | | Arithmetic | add / sub / mul / div / mod, mmul, mpow, Kronecker product | | Shape | transpose, concat, views, wrap existing typed arrays without copying | | Stats | mean, variance, norm, covariance, correlation, applyAlongAxis | | Factorization | LU, QR, SVD, EVD, Cholesky, NIPALS | | Solvers | solve, inverse, pseudoInverse, determinant | | Special types | SymmetricMatrix, DistanceMatrix |

Type definitions ship with the package (matrix.d.ts).


Quick start

ESM:

import { Matrix } from 'matrix-ops-core';

const A = Matrix.eye(3);
const b = Matrix.columnVector([1, 2, 3]);

CommonJS:

const { Matrix } = require('matrix-ops-core');

Browser (UMD, via unpkg / jsDelivr): matrix.umd.js.


Building matrices

import { Matrix } from 'matrix-ops-core';

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

const empty = Matrix.zeros(4, 4);
const identity = Matrix.eye(4);
const diagonal = Matrix.diag([3, 5, 7]);
const noise = Matrix.rand(8, 8, { random: Math.random });

fromRows.rows;    // 2
fromRows.columns; // 3
fromRows.get(1, 2); // 4
fromRows.set(0, 1, 9);

wrap() puts a matrix interface over an existing 1D or 2D array so you can reuse buffers:

import { wrap } from 'matrix-ops-core';

const buffer = Float64Array.from([1, 2, 3, 4, 5, 6]);
const view = wrap(buffer, { rows: 2 });
view.set(0, 0, 10); // writes through to `buffer`

Arithmetic

Static methods return a new matrix. Instance methods mutate in place.

import { Matrix } from 'matrix-ops-core';

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

Matrix.add(P, Q);  // new matrix
P.add(Q);          // P is updated

P.mmul(Q);         // matrix product
P.mul(0.5);        // scale
P.mpow(3);         // P³ via exponentiation by squaring

Element-wise math follows Math.* names: abs, exp, log, sqrt, sin, cos, and the rest of the standard set. Call them statically (Matrix.exp(P)) or in place (P.exp()).

Reductions and geometry:

P.mean();
P.norm();          // Frobenius
P.transpose();
P.diag();
P.concat(Q, 'column');
P.applyAlongAxis((col) => col.reduce((s, v) => s + v, 0), 'column');

Linear systems

import { Matrix, inverse, solve, pseudoInverse, determinant } from 'matrix-ops-core';

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

const x = solve(A, b);
const Ainv = inverse(A);
determinant(A);

// Rank-deficient / rectangular: SVD-based inverse
const tall = new Matrix([
  [1, 0],
  [1, 1],
  [0, 1],
]);
inverse(tall, true);
tall.pseudoInverse();

solve uses LU when the left-hand side is square and QR otherwise. Pass true as the third argument to force SVD (useful when the system is singular).


Factorizations

import {
  Matrix,
  LU,
  QR,
  SVD,
  EVD,
  CHO,
  NIPALS,
} from 'matrix-ops-core';

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

const { lowerTriangularMatrix: L, upperTriangularMatrix: U } = new LU(M);
const { orthogonalMatrix: Q, upperTriangularMatrix: R } = new QR(M);

const svd = new SVD(M);
svd.diagonal;      // singular values
svd.leftSingularVectors;
svd.rightSingularVectors;

const evd = new EVD(M);
evd.realEigenvalues;
evd.eigenvectorMatrix;

new CHO(M).lowerTriangularMatrix;

const nipals = new NIPALS(M);
nipals.t; // scores
nipals.p; // loadings

Full class names (LuDecomposition, QrDecomposition, SingularValueDecomposition, …) are exported alongside the short aliases.


Symmetric and distance matrices

import { SymmetricMatrix, DistanceMatrix } from 'matrix-ops-core';

const S = SymmetricMatrix.ones(4);
S.set(0, 3, 2); // also sets (3, 0)

const D = DistanceMatrix.fromCompact([1.2, 0.8, 3.1]);

Stats helpers

import { Matrix, covariance, correlation } from 'matrix-ops-core';

const samples = new Matrix([
  [1.0, 2.1, 0.4],
  [1.2, 1.9, 0.5],
  [0.8, 2.4, 0.3],
  [1.1, 2.0, 0.6],
]);

covariance(samples);
correlation(samples);

Scripts

npm test          # unit tests, eslint, prettier
npm run compile   # rollup bundles

License

MIT — jamesmorse82