Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ankane/npy
Save and load NumPy npy and npz files in Ruby
https://github.com/ankane/npy
Last synced: about 1 month ago
JSON representation
Save and load NumPy npy and npz files in Ruby
- Host: GitHub
- URL: https://github.com/ankane/npy
- Owner: ankane
- License: mit
- Created: 2019-09-13T04:53:02.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-26T20:16:48.000Z (9 months ago)
- Last Synced: 2024-03-24T19:07:41.000Z (6 months ago)
- Language: Ruby
- Homepage:
- Size: 42 KB
- Stars: 28
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Npy
Save and load NumPy `npy` and `npz` files in Ruby - no Python required
:fire: Uses [Numo](https://github.com/ruby-numo/numo-narray) for blazing performance
[![Build Status](https://github.com/ankane/npy/actions/workflows/build.yml/badge.svg)](https://github.com/ankane/npy/actions)
## Installation
Add this line to your application’s Gemfile:
```ruby
gem "npy"
```## Getting Started
### npy
`npy` files contain a single array
Save an array
```ruby
x = Numo::Int32[0..9]
Npy.save("x.npy", x)
```Load an `npy` file
```ruby
x = Npy.load("x.npy")
```Load an `npy` string
```ruby
byte_str = File.binread("x.npy")
x = Npy.load_string(byte_str)
```### npz
`npz` files contain multiple arrays
Save multiple arrays
```ruby
x = Numo::Int32[0..9]
y = x * 2
Npy.save_npz("data.npz", x: x, y: y)
```Load an `npz` file
```ruby
data = Npy.load_npz("data.npz")
```Get keys
```ruby
data.keys
```Get an array
```ruby
data["x"]
```Arrays are lazy loaded for performance
## Resources
- [npy format](https://docs.scipy.org/doc/numpy/reference/generated/numpy.lib.format.html#module-numpy.lib.format)
- [NumPy data types](https://docs.scipy.org/doc/numpy/user/basics.types.html)
- [Numo::NArray docs](https://ruby-numo.github.io/narray/narray/Numo/NArray.html)## History
View the [changelog](https://github.com/ankane/npy/blob/master/CHANGELOG.md)
## Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- [Report bugs](https://github.com/ankane/npy/issues)
- Fix bugs and [submit pull requests](https://github.com/ankane/npy/pulls)
- Write, clarify, or fix documentation
- Suggest or add new featuresTo get started with development:
```sh
git clone https://github.com/ankane/npy.git
cd npy
bundle install
bundle exec rake test
```