The library implements a large subset of numpy operations
// Feature 1: A parsing system that can interpret numpy code as ndarray-js instructions x = np`np.exp(0.5 * np.linspace(0, 1, 100).reshape(5, 4, 5)).mean(axis=0)` y = np`(${x} * ${x}) / 2`
// Equivalent code: x = np.exp(0.5 * np.linspace(0, 1, 100).reshape(5, 4, 5)).mean({axis:0}) y = np.divide(np.multiply(x * x), 2)
// Feature 2. Handling of args and kwargs following numpy order x = np.geomspace(1, 10, 100).reshape([10,10]) x.mean({axis: -1, keepdims:true}) x.mean(-1, true) x.mean(-1, {keepdims:true}) np.mean(x, {axis: -1})
// Feature 3. All types of indexing: (number, start:end:step, ':', '...', list of indices, NDArray boolean mask, NDArray boolean mask, NDArray indices) y = x.index(2, ':', mask, '...', indices, '-1:-1:-2', -1); y = np`${x}[2, :, ${mask}, ..., ${indices}, -1:-1:-2, -1]`;
Description
Welcome to the documentation of
ndarray-jsndarray-js is a reimplementation of numpy for javascript that aims to make the coding experience as similar to numpy as possible.
Interactive demo:
Errors:
Console output:
SVG outputs:
Features
The library implements a large subset of numpy operations
API Index
Browser usage
In html:
Or press F12 and play with the browser console directly.
Node usage
Installation:
Use in nodejs with require:
Use in nodejs with typescript (run with ts-node or compile with tsc):
Use in Jupyter notebooks:
You need to install the ipykernel (the setup is a bit more complex).
Example notebook: https://github.com/caph1993/numpy-js/blob/main/notebooks/normal-scatter.ipynb