Skip to content

AdityaSarwade/npyjs

This branch is 11 commits behind aplbrain/npyjs:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

2f1fb64 · Jun 7, 2023

History

78 Commits
May 2, 2022
Jun 7, 2023
Apr 24, 2022
Sep 16, 2016
May 6, 2019
Sep 16, 2016
Mar 2, 2023
Apr 24, 2022
Mar 2, 2023
Mar 2, 2023
Mar 2, 2023

Repository files navigation

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

  • Create a new npyjs object.
let n = new npyjs();
  • This object can now be used load .npy files. Arrays can be returned via a JavaScript callback, so usage looks like this:
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.`
    );
});
  • You can also use this library promise-style using either .then or async await:
n.load("test.npy").then((res) => {
    // res has { data, shape, dtype } members.
});
const npyArray = await n.load("test.npy");

Accessing multidimensional array elements

  • You can conveniently access multidimensional array elements using the 'ndarray' library:
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

About

Read numpy .npy files in JavaScript

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 91.5%
  • Python 8.5%