Skip to content

Instantly share code, notes, and snippets.

@jelmervdl
Created November 7, 2023 15:07
Show Gist options
  • Save jelmervdl/44a45488ae836c2e47522a468b697d64 to your computer and use it in GitHub Desktop.
Save jelmervdl/44a45488ae836c2e47522a468b697d64 to your computer and use it in GitHub Desktop.
Inspect npz from a distance
#!/usr/bin/env python3
from zipfile import ZipFile
from numpy.lib.format import read_magic, _read_array_header
import httpio
import csv
import sys
out = csv.DictWriter(sys.stdout, ['name', 'shape', 'dtype'], dialect='excel-tab')
with httpio.open(sys.argv[1]) as zfh:
archive = ZipFile(zfh)
for filename in archive.namelist():
if filename.endswith('.npy'):
with archive.open(filename) as fh:
version = read_magic(fh)
shape, order, dtype = _read_array_header(fh, version)
out.writerow({
'name': filename,
'shape': repr(shape),
'dtype': dtype.name
})
@jelmervdl
Copy link
Author

pip install numpy httpio

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