How do I view data object contents within an npz file?

Viewed 11234

I am using Spyder IDE and Python 2.7.

I have a npz file called data.npz which was given to me. I want to load this file into Spyder and view whatever is inside.

To start I've done this:

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

In my Variable Explorer in Spyder, I have a variable with the name "data" and the type "object". When I double-click on this variable, Spyder gives an error saying "object arrays are currently not supported".

When I just type

data

I get something like this:

array({'a': array([ 1,2,3, ...,
         4,5,6]), 'b': 10, 'c': array([-1,-2,-3]), 'd': 25, 'e': 1}, dtype=object)

How do I access 'a', 'b', 'c', 'd', etc?

3 Answers

to obtain a list of all the constituent files, simply use:

$ data.files

Try accessing each key in the dictionary as follows:

data['a']  
data['b']

print(data.files) will give you a list of arrays contained within the npz file. you can then use the data['a'] to view contents of a, and data['b'] to view b, so on and so forth

Related