Skip to main content
If you already know NumPy in Python, you will feel at home with numpy-ts. This guide covers the key differences so you can migrate existing code or switch between the two with confidence.

Importing

Creating arrays

Shape arguments use arrays in numpy-ts, not separate arguments or tuples. Write np.zeros([3, 3]), not np.zeros(3, 3) or np.zeros((3, 3)).

Arithmetic

numpy-ts does not overload JavaScript operators. Use np.add(a, b) or a.add(b) instead of a + b. Method chaining (.add(), .reshape(), etc.) is available on NDArray from the full entry point. See Tree-Shaking & Bundle Size for details on the two entry points.

Indexing and slicing

This is the biggest syntax change. Python uses bracket notation with colons; numpy-ts uses a .slice() method with string arguments.

Slicing syntax reference

Reshaping

Reductions

Linear algebra

The linalg namespace is identical between NumPy and numpy-ts. No changes needed for these calls beyond the import.

Random

As of v1.2.0, numpy-ts uses the same RNGs as NumPy (MT19937 for the legacy API, PCG64 for the modern API). Random outputs now match NumPy exactly for all distributions given the same seed.

FFT

File I/O

numpy-ts/node is deprecated as of v1.2.0 (it still works as an alias). All 22 file I/O functions are now available from the main numpy-ts entry point on Node, Bun, and Deno.

Common gotchas

Supported dtypes

numpy-ts supports 14 data types that map to JavaScript TypedArrays:
When working with int64 or uint64, array elements are BigInt values. Use the n suffix for literals: np.array([1n, 2n, 3n], 'int64').

What about missing NumPy features?

numpy-ts covers 476 of 507 NumPy functions (94%). A few categories have partial coverage:
  • Structured arrays / record dtypes — not supported (JS has no equivalent)
  • String operations (np.char) — not supported (use native JS string methods)
  • np.ma (masked arrays) — not supported yet
  • np.matrix — deprecated in NumPy itself; use 2D NDArray instead
For everything else — math, linear algebra, FFT, random, sorting, sets, polynomials, bitwise operations, I/O — numpy-ts has you covered.

Next steps

Quickstart

Hands-on tutorial covering all major features.

API Reference

Complete function reference organized by category.

Tree-Shaking

Full library vs core: which entry point is right for you?