Skip to content
Save and load NumPy npy and npz files in Ruby
Ruby Python
Branch: master
Clone or download
Latest commit a61a202 Sep 23, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.gitignore
.travis.yml
CHANGELOG.md
Gemfile
LICENSE.txt
README.md
Rakefile
npy.gemspec

README.md

Npy

Save and load NumPy npy and npz files in Ruby - no Python required

🔥 Uses Numo for blazing performance

Build Status

Installation

Add this line to your application’s Gemfile:

gem 'npy'

Getting Started

npy

npy files contain a single array

Save an array

x = Numo::Int32[0..9]
Npy.save("x.npy", x)

Load an npy file

x = Npy.load("x.npy")

Load an npy string

byte_str = File.binread("x.npy")
x = Npy.load_string(byte_str)

npz

npz files contain multiple arrays

Save multiple arrays

x =  Numo::Int32[0..9]
y = x * 2
Npy.save_npz("data.npz", x: x, y: y)

Load an npz file

data = Npy.load_npz("data.npz")

Get keys

data.keys

Get an array

data["x"]

Arrays are lazy loaded for performance

Resources

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

You can’t perform that action at this time.