Skip to content

Instantly share code, notes, and snippets.

@lmmx
Created June 18, 2024 17:52
Show Gist options
  • Save lmmx/17bbfcddd82247b8451129df6af335e4 to your computer and use it in GitHub Desktop.
Save lmmx/17bbfcddd82247b8451129df6af335e4 to your computer and use it in GitHub Desktop.
Simple `.npy` file format reading (to benchmark against `np.load`)
[package]
name = "hello_npy"
version = "0.1.0"
edition = "2021"
[dependencies]
npyz = "0.8.3"
use npyz::NpyFile;
fn read_npy_file(file_path: &str) -> Vec<f64> {
let reader = std::io::BufReader::new(std::fs::File::open(file_path).unwrap());
NpyFile::new(reader).unwrap().into_vec().unwrap()
}
fn main() {
let file_path = "/path/to/your/file.npy";
let _data = read_npy_file(file_path);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment