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

numpy-ts currently uses different RNGs than NumPy. This means that the generated random numbers will not match NumPy’s output, even with the same seed. Statistical properties (distributions, means, variances) will be the same, but exact sequences will differ.

FFT

File I/O

File I/O is only available from numpy-ts/node. The main numpy-ts entry point exports buffer-based parsers and serializers (parseNpy, serializeNpy) that work in any environment.

Common gotchas

Supported dtypes

numpy-ts supports 13 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?