Complete NumPy for TypeScript
The most comprehensive NumPy implementation for TypeScript and JavaScript. Write numerical computing code with the same API you already know from Python — fully type-safe, tree-shakeable, and validated against NumPy itself.
npm
yarn
pnpm
Why numpy-ts?
Quick Example
import * as np from 'numpy-ts';
// Create arrays -- just like NumPy
const a = np.array([[1, 2], [3, 4]]);
const b = np.zeros([2, 2]);
// Broadcasting works as expected
const c = a.add(1); // [[2, 3], [4, 5]]
const d = a.multiply(2); // [[2, 4], [6, 8]]
// Linear algebra
const inv = np.linalg.inv(a);
const det = np.linalg.det(a); // -2
// Dot products and matrix multiplication
const e = np.dot(a, np.array([[5, 6], [7, 8]])); // [[19, 22], [43, 50]]
// Reshape, slice, and manipulate
const r = np.arange(12);
const grid = np.reshape(r, [3, 4]);
Get Started
Coming from NumPy?
numpy-ts mirrors the NumPy API as closely as possible. Most code translates directly:
Python (NumPy)
TypeScript (numpy-ts)
import numpy as np
a = np.array([[1, 2], [3, 4]])
b = np.linalg.inv(a)
c = np.dot(a, b) # identity matrix
d = np.sum(a, axis=0) # [4, 6]
e = a[0, :] # [1, 2]
import * as np from 'numpy-ts';
const a = np.array([[1, 2], [3, 4]]);
const b = np.linalg.inv(a);
const c = np.dot(a, b); // identity matrix
const d = np.sum(a, { axis: 0 }); // [4, 6]
const e = a.get([0, ':']); // [1, 2]
See the NumPy Migration Guide for a complete translation reference.
numpy-ts is brought to you by