How to open a .npz file

First I want to say that I am completely new to programming and Python.

Someone will send me a .npz file. Is there anyone who could explain to me how to open this file. Or what code should I write. I've met for a long time, but I just don't understand how to open it.

Thanks in advance.

+11


source to share


4 answers


use this in python3:



from numpy import load

data = load('out.npz')
lst = data.files
for item in lst:
    print(item)
    print(data[item])

      

+11


source


You want to use numpy.load()

with a context manager:

with numpy.load('foo.npz') as data:
    a = data['a']

      

You should use a context manager here as the documentation states:



the returned instance of the class NpzFile

must be closed to avoid leaking file descriptors.

and the context manager will handle this for you.

+4


source


Use the function : load

import numpy as np
data = np.load('your_file.npz')

      

+2


source


import numpy as np

data = np.load ('imdb.npz', allow_pickle = True)
lst = data.files

for item in lst:
    print (item)
    print (data [item])
0


source







All Articles