Last active
October 13, 2015 16:18
-
-
Save julienr/4222988 to your computer and use it in GitHub Desktop.
npycat : cat-like tool for numpy .npy files
This file contains 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
#!/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