numpy-ts gives you two choices for how to import it. The right choice depends on whether you care more about developer experience or bundle size.Documentation Index
Fetch the complete documentation index at: https://numpyts.dev/llms.txt
Use this file to discover all available pages before exploring further.
The full library (numpy-ts)
NDArray objects that support method chaining — the same fluent style you are used to from NumPy:
np.add, np.reshape, np.sum, etc.) is also available as a method on the array itself (.add(), .reshape(), .sum()). This makes code shorter and more readable.
The trade-off: importing anything from numpy-ts pulls the entire library into your bundle (~200-300 KB minified). The bundler cannot tree-shake it because all 100+ methods are attached to the NDArray class at import time.
~200-300 KB is still small compared to alternatives that ship WebAssembly or native modules. For Node.js servers, scripts, and most applications this is perfectly fine.
- You are building an application (not a library)
- You are running on Node.js or Bun where bundle size is irrelevant
- You want the best developer experience with method chaining
- You are using many functions from across the API
The tree-shakeable core (numpy-ts/core)
NDArrayCore objects — a minimal array class with properties (shape, dtype, ndim, data, T, etc.) but no operation methods. Instead, you use standalone functions for everything:
| What you import | Bundle size |
|---|---|
array + zeros | ~10 KB |
Basic arithmetic (add, subtract, multiply) | ~15 KB |
Arithmetic + reductions (sum, mean, std) | ~20 KB |
Arithmetic + linear algebra (dot, inv, solve) | ~40 KB |
Full library (any import from numpy-ts) | ~200-300 KB |
- You are building a browser app where every kilobyte matters
- You are publishing a library on npm (let your consumers choose their bundle)
- You only need a small subset of numpy-ts functions
What about Node.js file I/O?
There is a third entry point,numpy-ts/node, that adds file system operations (load, save, savez, loadtxt, savetxt) on top of the full library. It behaves like numpy-ts but also includes Node.js fs bindings.
NDArray vs NDArrayCore
The two array types share the same core —NDArray extends NDArrayCore. This means:
- Every
NDArrayis anNDArrayCore(you can pass it to any function that acceptsNDArrayCore) NDArrayCoreis not anNDArray(it lacks the chaining methods)- Both types expose the same properties:
shape,ndim,size,dtype,data,strides,flags,base,T,itemsize,nbytes
numpy-ts/core accept both types as input:
Side-by-side comparison
The same operation written with both entry points:Quick reference
numpy-ts | numpy-ts/core | numpy-ts/node | |
|---|---|---|---|
| Array class | NDArray | NDArrayCore | NDArray |
| Method chaining | Yes | No | Yes |
| Tree-shakeable | No | Yes | No |
| Bundle size | ~200-300 KB | ~10-40 KB | ~200-300 KB + fs |
| File I/O | Browser only | Browser only | Node.js + Browser |
| Best for | Apps, scripts | Libraries, browsers | Node.js with files |