🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

numpy-loader

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

numpy-loader

A webpack loader for binary numpy .npy files

1.2.0
latest
Source
npm
Version published
Weekly downloads
62
63.16%
Maintainers
1
Weekly downloads
 
Created
Source

numpy-loader

npm-version

A webpack loader for binary numpy .npy files

Usage

Configure the loader in your webpack.config.js under module > rules, e.g. like this:

{
  test: /\.(npy|npc)$/,
  exclude: /node_modules/,
  loader: 'numpy-loader',
  options: {
    outputPath: 'assets/data'
  }
}

You can specify an outputPath that will be used during compilation.

You can now load .npy files as ndarrays in your JS code simply by requireing them. There are two modes, for small and large npy files respectively:

Small files

Load small .npy files directly from the webpack bundle using embed=true. These files will be base64 encoded and become a part of your webpack bundle.

let npyarray = require("numpy-loader?embed=true!./data/array_uint8.npy");
console.log("Loaded array in JS directly from packed module: " + npyarray.constructor.name);
console.log(npyarray);

Large files

You might not want to embed particularly large files in your webpack bundle. You can specify embed=false (or nothing; it's the default) to copy your .npy files to your output directory and load them as binary files from your server at runtime instead. Thus you need to use the #load() callback like this:

const npyarray = require("numpy-loader?embed=false!./data/array_uint8.npy")

npyarray.load( (array) => {
  console.log("Loaded an .npy array in JS!");
  console.log(array);
})

FAQs

Package last updated on 04 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts