aplbrain / npyjs

Read numpy .npy files in JavaScript
https://aplbrain.github.io/npyjs/
Apache License 2.0
77 stars 21 forks source link
3d javascript jhuapl nodejs npy npy-files numpy

npy.js

Read .npy files directly in JS

GitHub Workflow Status

Installation

Include npy.js in your project directly, or:

yarn add npyjs
# npm i npyjs

Import

import npyjs from "npyjs";

Usage

let n = new npyjs();
n.load("my-array.npy", (array, shape) => {
    // `array` is a one-dimensional array of the raw data
    // `shape` is a one-dimensional array that holds a numpy-style shape.
    console.log(
        `You loaded an array with ${array.length} elements and ${shape.length} dimensions.`
    );
});
n.load("test.npy").then((res) => {
    // res has { data, shape, dtype } members.
});
const npyArray = await n.load("test.npy");

Accessing multidimensional array elements

import ndarray from "ndarray";
const npyArray = ndarray(data, shape);
npyArray.get(10, 15)

Unless otherwise specified, all code inside of this repository is covered under the license in LICENSE.

Please report bugs or contribute pull-requests on GitHub.


Made with ♥ at JHU APL