Struct ndarray_npy::NpzWriter[][src]

pub struct NpzWriter<W: Write + Seek> { /* fields omitted */ }
Expand description

Writer for .npz files.

Note that the inner ZipWriter is wrapped in a BufWriter when writing each array with .add_array(). If desired, you could additionally buffer the innermost writer (e.g. the File when writing to a file) by wrapping it in a BufWriter. This may be somewhat beneficial if the arrays are large and have non-standard layouts but may decrease performance if the arrays have standard or Fortran layout, so it’s not recommended without testing to compare.

Example

use ndarray::{array, Array1, Array2};
use ndarray_npy::NpzWriter;
use std::fs::File;

let mut npz = NpzWriter::new(File::create("arrays.npz")?);
let a: Array2<i32> = array![[1, 2, 3], [4, 5, 6]];
let b: Array1<i32> = array![7, 8, 9];
npz.add_array("a", &a)?;
npz.add_array("b", &b)?;
npz.finish()?;

Implementations

Create a new .npz file without compression. See numpy.savez.

Creates a new .npz file with compression. See numpy.savez_compressed.

Adds an array with the specified name to the .npz file.

Calls .finish() on the zip file and .flush() on the writer, and then returns the writer.

This finishes writing the remaining zip structures and flushes the writer. While dropping will automatically attempt to finish the zip file and (for writers that flush on drop, such as BufWriter) flush the writer, any errors that occur during drop will be silently ignored. So, it’s necessary to call .finish() to properly handle errors.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.