pythonnumpy

Open and view .npz file in Python


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.)?


Solution

  • 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.