np.savez
saves only numpy arrays. If you give it a dict, it will call np.array(yourdict)
before saving it. So this is why you see something like type(arrays['header'])
as np.ndarray
:
arrays = np.load(filename)
h = arrays['header'] # square brackets!!
>>> h
array({'POSITION': (23, 54), 'TIME': 23.5}, dtype=object)
You'll notice if you look at it though, that it is a 0-dimensional, single-item array, with one dict inside:
>>> h.shape
()
>>> h.dtype
dtype('O') # the 'object' dtype, since it's storing a dict, not numbers.
so you could work around by doing this:
h = arrays['header'][()]
The mysterious indexing gets the one value out of a 0d array:
>>> h
{'POSITION': (23, 54), 'TIME': 23.5}