26

I have an unknown .npz file and would like to see whats inside. I am very new to Python.

>>> import numpy
>>> b = numpy.load('data.npz')
>>> print(b.files)
['arr_1', 'arr_0', 'arr_3', 'arr_2']

How do I see what these arr_i contain (i.e. dimension, values, etc.)?

4

2 Answers 2

27
np.savez_compressed('filename.npz', array1=array1, array2=array2)
b = np.load('filename.npz')

And do b['array_1'], b['array_2'] and so on to retrieve data from each array.

1
  • As an additional note, if we use with open(filename, 'rb') as f: b=np.load(f) , it gives error. So, we should just simply use np.load(filename) :)
    – mah65
    Sep 15, 2021 at 5:54
16

Python provides "npzviewer" to open .npz files

pip install npzviewer

npzviewer [-h] [-v] [npzfile]

https://pypi.org/project/npzviewer/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.