Expand description
I/O for arrays: .npy, .npz and CSV files, like np.save, np.load, np.savez,
np.savetxt and np.loadtxt.
Every function returns crate::Result: file problems are crate::Error::Io, a file
whose dtype differs from the requested element type is crate::Error::DType, and malformed
content is crate::Error::Format or crate::Error::Parse.
use rustnum as np;
let a = np::array![[1.5, 2.5], [3.5, 4.5]];
let bytes = np::io::to_npy_bytes(&a);
let b: np::Array<f64> = np::io::from_npy_bytes(&bytes).unwrap();
assert_eq!(a, b);§Architecture
npy(private):.npyformat v1.0/v2.0 on(Vec<T>, shape).csv(private): CSV parse and format on(Vec<T>, shape).api: the public functions, which wrap those kernels and returnArray.npz(private module): ZIP/DEFLATE layer behindsavez,savez_compressed,load_npzandNpzFile, which are re-exported here.
Structs§
- NpzFile
- An opened
.npzfile whose arrays are decompressed only when requested, likenp.load(path)on a.npz(NpzFilein NumPy).
Functions§
- from_
npy_ bytes - Deserializes an array from
.npybytes in memory (seeload_npyfor the rules). - load_
csv - Loads delimited text as a 1-d or 2-d array, like
np.loadtxt(path, delimiter=..., skiprows=...). - load_
npy - Loads an array from a
.npyfile, likenp.load(path). - load_
npz - Loads every array of an
.npzfile, likedict(np.load(path)). - save_
csv - Saves a 1-d or 2-d array as delimited text, like
np.savetxt(path, a, delimiter=...). - save_
npy - Saves an array to a
.npyfile, likenp.save(path, a). - savez
- Saves several named arrays into one uncompressed
.npzfile, likenp.savez(path, **arrays). - savez_
compressed - Saves several named arrays into one DEFLATE-compressed
.npzfile, likenp.savez_compressed(path, **arrays). - to_
npy_ bytes - Serializes an array to
.npybytes in memory, likenp.saveinto a buffer.