Sha256: 6e18644e0857fa08f086d3a2385e4c30c4bcce665b7aa5fdd74db56ca4dddcbf

Contents?: true

Size: 1.77 KB

Versions: 1

Compression:

Stored size: 1.77 KB

Contents

# 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 features

To get started with development:

```sh
git clone https://github.com/ankane/npy.git
cd npy
bundle install
bundle exec rake test
```

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
npy-0.4.0 README.md