|
преди 1 месец | |
---|---|---|
.. | ||
docs | преди 1 месец | |
test | преди 1 месец | |
CHANGELOG.md | преди 1 месец | |
LICENSE | преди 1 месец | |
README.md | преди 1 месец | |
index.d.ts | преди 1 месец | |
index.js | преди 1 месец | |
package.json | преди 1 месец | |
tsconfig.json | преди 1 месец |
Read .npy files from numpy in Node/JS.
Include npy.js in your project directly, or:
yarn add npyjs
# npm i npyjs
import npyjs from "npyjs";
let n = new npyjs();
// Or with options:
let n = new npyjs({ convertFloat16: false }); // Disable float16 to float32 conversion
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");
import ndarray from "ndarray";
const npyArray = ndarray(data, shape);
npyArray.get(10, 15);
The library supports the following NumPy data types:
int8
, uint8
int16
, uint16
int32
, uint32
int64
, uint64
(as BigInt)float32
float64
float16
(converted to float32 by default)By default, float16 arrays are automatically converted to float32 for compatibility, since JavaScript doesn't natively support float16. You can control this behavior with the constructor options:
// Default behavior - float16 is converted to float32
const n1 = new npyjs();
// Keep float16 as raw uint16 values without conversion
const n2 = new npyjs({ convertFloat16: false });
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.