Created
November 7, 2023 15:07
-
-
Save jelmervdl/44a45488ae836c2e47522a468b697d64 to your computer and use it in GitHub Desktop.
Inspect npz from a distance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pip install numpy httpio