Skip to content

Instantly share code, notes, and snippets.

@adityaiitb
Last active July 30, 2020 15:13
Show Gist options
  • Save adityaiitb/6c4d1ae12851c506d2d6861e7c17001a to your computer and use it in GitHub Desktop.
Save adityaiitb/6c4d1ae12851c506d2d6861e7c17001a to your computer and use it in GitHub Desktop.
Create a numpy npz file

The .npz file format is used to save several numpy arrays into a single zipped file. Documentation.

import numpy as np

a = np.array([42])
b = np.array([2, 3, 5, 7, 9]) 

with open("foo.npz", "wb") as f:
    np.savez(f, a, b)

The .npz file can be unzipped to get .npy files for each array.

unzip foo.npz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment