Skip to content

Instantly share code, notes, and snippets.

@julienr
Last active October 13, 2015 16:18
Show Gist options
  • Save julienr/4222988 to your computer and use it in GitHub Desktop.
Save julienr/4222988 to your computer and use it in GitHub Desktop.
npycat : cat-like tool for numpy .npy files
#!/home/julien/tm/v2/venv/bin/python
"""
Cat-like utility for .npy files
"""
import numpy as np
import sys
def print_arr(a):
print 'dtype : ', a.dtype
print 'shape : ', a.shape
print a
if len(sys.argv) < 2:
print 'usage: npycat <filename>'
sys.exit(-1)
np.set_printoptions(suppress=True, precision=6)
arr = np.load(sys.argv[1])
if hasattr(arr, 'files'): # npz
for k, v in arr.items():
print '==== %s ====' % k
print_arr(v)
else: # npy
print_arr(arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment