Skip to main content

Install the package

npm install numpy-ts

Requirements

EnvironmentMinimum Version
Node.js>= 20.1.0
BrowsersES2020+ (Chrome 80+, Firefox 78+, Safari 14+, Edge 80+)
TypeScript>= 5.0 (recommended)
numpy-ts has zero runtime dependencies. The installed size is the library itself.

CDN usage (browsers)

You can load numpy-ts directly in the browser without a build step:
<script type="module">
  import * as np from 'https://esm.sh/numpy-ts';

  const a = np.array([[1, 2], [3, 4]]);
  console.log(a);
</script>

Choose your entry point

numpy-ts ships three entry points. Pick the one that fits your use case:
Entry PointImport PathReturnsBundle SizeUse When
Fullnumpy-tsNDArray~200-300 KBYou want method chaining and the complete API
Corenumpy-ts/coreNDArrayCore~10-40 KBBundle size matters; you only need specific functions
Nodenumpy-ts/nodeNDArray~200-300 KB + fsYou need file I/O (load, save, savez) on Node.js
See the Tree-Shaking guide for a detailed comparison.

Full library (numpy-ts)

The default entry point. Functions return NDArray, which supports method chaining (.add(), .reshape(), .T, etc.).
import * as np from 'numpy-ts';

const a = np.array([1, 2, 3, 4]);
const b = a.add(10).reshape([2, 2]).T;  // Method chaining
Best for applications, scripts, and projects where developer experience matters more than bundle size.

Tree-shakeable core (numpy-ts/core)

Functions return NDArrayCore (no method chaining). Your bundler (webpack, Vite, esbuild, Rollup) will only include the functions you actually import.
import { array, add, reshape, transpose } from 'numpy-ts/core';

const a = array([1, 2, 3, 4]);
const b = transpose(reshape(add(a, 10), [2, 2]));
Best for libraries, frontend apps where every kilobyte counts, and when you only need a handful of functions.
Importing just array and add from numpy-ts/core results in a bundle around 10 KB minified. The full entry point is always ~200-300 KB regardless of what you use.

Node.js file I/O (numpy-ts/node)

Everything from numpy-ts plus file system operations for .npy, .npz, and text files.
import * as np from 'numpy-ts/node';

// Load and save .npy files
const arr = await np.loadNpy('data.npy');
await np.saveNpy('output.npy', arr);

// Load and save .npz archives
const { arrays } = await np.loadNpzFile('data.npz');
await np.savez('output.npz', { x: arr, y: arr });

// Text files
const data = await np.loadtxt('data.csv', { delimiter: ',' });
await np.savetxt('output.csv', data, { delimiter: ',' });
The numpy-ts/node entry point uses Node.js built-in fs modules. It will not work in browsers or edge runtimes.

Next steps