npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tfjs-npy-node

v0.4.1

Published

[![test](https://github.com/MaximeKjaer/tfjs-npy-node/actions/workflows/test.yml/badge.svg)](https://github.com/MaximeKjaer/tfjs-npy-node/actions/workflows/test.yml) [![npm](https://img.shields.io/npm/v/tfjs-npy-node)](https://www.npmjs.com/package/tfjs-n

Downloads

129

Readme

NumPy file parsing and serialization for TensorFlow.js

test npm

This is a fork of tfjs-npy, which adds:

  • New synchronous APIs
  • .npz parsing and serialization
  • Loading and saving files from disk
  • Ability to parse from Buffer and typed arrays (e.g. UInt8Array), in addition to ArrayBuffers

Note that because of support for .npz (which uses zlib for zipping), and for loading and saving files, this library is meant to be used in Node.js, not in the browser. If you want to convert to npy in the browser, consider using the original tfjs-npy.

See the Numpy docs for more information about the file format.

Installation

# Using npm
$ npm install tfjs-npy-node

# Using yarn
$ yarn add tfjs-npy-node

API

import * as tf from "@tensorflow/tfjs-core";
import { npy, npz } from "tfjs-npy-node";

////////////////
// .npy files //
////////////////

// Load a Tensor from a `.npy` file:
const tensor1: tf.Tensor = await npy.load("file.npy");

// Parse a Tensor from an `ArrayBuffer`, `Buffer` or typed array (e.g.
// `UInt8Array`) containing the bytes of a `.npy` file:
const npyArrayBuffer: ArrayBuffer = getArrayBufferFromSomewhere();
const tensor2: tf.Tensor = npy.parse(npyArrayBuffer);

// Save a tensor to a `.npy` file:
await npy.save("file2.npy", tensor2);

// Serialize a tensor to an `ArrayBuffer` containing the bytes of the `.npy`
// file:
const npyArrayBuffer2: ArrayBuffer = await npy.serialize(tensor1);
const npyArrayBuffer3: ArrayBuffer = npy.serializeSync(tensor2);

////////////////
// .npz files //
////////////////

// Load a Tensor from a `.npz` file:
const tensors1: tf.Tensor[] = await npz.load("file.npz");

// Parse a Tensor from an `ArrayBuffer`, `Buffer` or typed array (e.g.
// `UInt8Array`) containing the bytes of a `.npz` file:
const npzArrayBuffer: ArrayBuffer = getArrayBufferFromSomewhere();
const tensors2: tf.Tensor[] = npz.parse(npyArrayBuffer);

// Save a tensor to a `.npz` file:
await npz.save("file2.npz", tensors2);

// Serialize a tensor to an `ArrayBuffer` containing the bytes of the `.npy`
// file:
const npzArrayBuffer2: ArrayBuffer = await npz.serialize(tensors1);
const npzArrayBuffer3: ArrayBuffer = npz.serializeSync(tensors2);

Contributing

Getting started

Clone the repo, install dependencies, and run the tests:

$ git clone [email protected]:MaximeKjaer/tfjs-npy-node.git
$ cd tfjs-npy-node
$ npm install
$ npm run build
$ npm run test

Releasing a new version

If you have write access to the main branch of the repo, use npm version.

The package.json defines some tasks that are automatically executed when bumping the package version. You will need to have the GitHub CLI installed if you want the automatic release creation to work.