Npy
Save and load NumPy npy
and npz
files in Ruby - no Python required
:fire: Uses Numo::NArray for blazing performance
Installation
Add this line to your application’s Gemfile:
gem 'npy'
Getting Started
npy
npy
files contain a single array
Save an array
arr = Numo::Int32[0...10]
Npy.save("x.npy", arr)
Load an npy
file
arr = Npy.load("x.npy")
Load an npy
string
byte_str = File.binread("x.npy")
arr = Npy.load_string(byte_str)
npz
npz
files contain multiple arrays
Save multiple arrays
x = Numo::Int32[0...10]
y = x * 2
Npy.save_npz("mnist.npz", x: x, y: y)
Load an npz
file
arrs = Npy.load_npz("mnist.npz")
Get keys
arrs.keys
Get an array
arrs["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:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features