This crate provides support for reading/writing [ndarray
]'s ArrayBase
type
from/to [.npy
] and [.npz
] files. See the
documentation for more information.
This crate is a work-in-progress. It currently supports only a subset of
.npy
header descriptors and supports only primitive fixed-size integer,
floating point, and bool
types as the array element type. You can implement
the *Element
traits for your own types, but the next breaking release of this
library will probably change those traits.
Future plans include support for:
.npz
files. (Memory-mapped .npy
files are already
supported.)ndarray-npy
, check out the [npy
crate].npy
crate].To use with the default features:
toml
[dependencies]
ndarray-npy = "0.8"
The default
feature set includes the compressed_npz
feature, which enables
support for uncompresssed and compressed .npz
files. This requires a
dependency on the [zip
crate] and a compression backend crate.
To use without the default features:
toml
[dependencies]
ndarray-npy = { version = "0.8", default-features = false }
With default-features = false
, ndarray-npy
provides support only for .npy
files, not .npz
files. If you want .npz
file support, you can select
additional features:
npz
enables support for uncompressed .npz
files. This requires a
dependency on the [zip
crate].compressed_npz
enables support for uncompressed and compressed .npz
files. This requires a dependency on the [zip
crate] and a compression
backend crate.For example, you can use just the npz
feature:
toml
[dependencies.ndarray-npy]
version = "0.8"
default-features = false
features = ["npz"]
Library authors should specify their dependency on ndarray-npy
like this:
toml
[dependencies.ndarray-npy]
version = "0.8"
default-features = false
features = [FEATURES_LIST_HERE]
where the features
list is one of the following:
[]
if your crate does not depend on .npz
file support["npz"]
if your crate depends on .npz
file support but not compression["compressed_npz"]
if your crate depends on .npz
file support with compression0.8.0
ndarray
0.15.py_literal
0.4.0.7.2
.finish()
method to NpzWriter
. All users of NpzWriter
should
call this method, after the write of the last array, in order to properly
handle errors. (Without calling .finish()
, dropping will automatically
attempt to finish the file, but errors will be silently ignored.)write_npy
convenience function and the NpzWriter::add_array
method to buffer writes using BufWriter
. This significantly improves
write performance for arrays which are not in standard or Fortran layout.
The docs of WriteNpyExt::write_npy
have also been updated to recommend
that users wrap the writer in a BufWriter
. Thanks to @bluss for
mentioning the unbuffered writes issue.WriteNpyExt::write_npy
to always call .flush()
before
returning. This is convenient when the writer passed to
WriteNpyExt::write_npy
is wrapped in a BufWriter
.0.7.1
.npy
files, primarily for use
with memory-mapped files. See the ViewNpyExt
and ViewMutNpyExt
extension traits. By @n3vu0r and @jturner314.write_zeroed_npy
..npy
file header. Before, if the
number of bytes of data was more than isize::MAX
, the implementation
would attempt to create the array anyway and panic. Now, it detects this
case before attempting to create the array and returns
Err(ReadNpyError::LengthOverflow)
instead.0.7.0
ndarray
0.14.0.6.0
write_npy
to take the array by reference instead of by value, by
@flaghacker.0.5.0
ndarray
0.13.read_npy
and write_npy
convenience functions.npy
format version 3.0.ReadableElement::read_vec
to ::read_to_end_exact_vec
.Error
type from Readable/WritableElement
and updating to the new style
of std::error::Error
implementation.0.4.0
bool
, by @tobni and
@jturner314.zip
0.5.compressed_npz_default
feature to compressed_npz
because
the zip
crate no longer allows the user to select the compression
backend.0.3.0
ndarray
0.12.num-traits
0.2 (replacing dependency on num
).py_literal
0.2.0.2.0
zip
0.4..npz
files user-selectable.default-features = false, features = ["compressed_npz"]
.0.1.1
0.1.0
Please feel free to create issues and submit PRs. PRs adding more tests would be especially appreciated.
Copyright 2018–2021 Jim Turner and ndarray-npy
developers
Licensed under the Apache License, Version 2.0, or the MIT license, at your option. You may not use this project except in compliance with those terms.