Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/aplbrain/npyjs

Read numpy .npy files in JavaScript
https://github.com/aplbrain/npyjs

3d javascript jhuapl nodejs npy npy-files numpy

Last synced: 6 days ago
JSON representation

Read numpy .npy files in JavaScript

Awesome Lists containing this project

README

        

npy.js


Read .npy files directly in JS





GitHub Workflow Status

## Installation

Include npy.js in your project directly, or:

```shell
yarn add npyjs
# npm i npyjs
```

## Import

```javascript
import npyjs from "npyjs";
```

## Usage

- Create a new npyjs object.

```javascript
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:

```javascript
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:

```javascript
n.load("test.npy").then((res) => {
// res has { data, shape, dtype } members.
});
```

```javascript
const npyArray = await n.load("test.npy");
```

## Accessing multidimensional array elements

- You can conveniently access multidimensional array elements using the 'ndarray' library:

```javascript
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](LICENSE).

Please report bugs or contribute pull-requests on [GitHub](https://github.com/aplbrain/npyjs).

---

Made with ♥ at JHU APL