A side-by-side guide for Python NumPy users moving to numpy-ts in TypeScript/JavaScript.
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.
c = a + bd = a * be = a ** 2f = np.sqrt(a)g = np.dot(a, b)
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.
This is the biggest syntax change. Python uses bracket notation with colons; numpy-ts uses a .slice() method with string arguments.
Copy
Ask AI
a = np.arange(12).reshape(3, 4)a[0, 2] # Single elementa[0:2, :] # First 2 rowsa[:, 1:3] # Columns 1-2a[::-1, :] # Reverse rowsa[-1, :] # Last rowa[1] # Second row (implicit full slice on remaining dims)
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.
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.