[Numpy-discussion] Question about np.savez
David Warde-Farley
dwf at cs.toronto.edu
Tue Sep 1 20:36:38 EDT 2009
On 1-Sep-09, at 9:08 AM, Pauli Virtanen wrote:
> Tue, 01 Sep 2009 12:07:36 +0000, jorgesmbox-ml kirjoitti:
>> I know the documentation states that np.savez saves numpy arrays,
>> so my
>> question relates to misusing it. Before reading the doc in detail,
>> and
>> after reading about pickle and other options to make data
>> persistent, I
>> passed np.savez a list of ndarrays. It didn't complain, but when I
>> loaded the data back, the list had been turned into an ndarray. Is
>> this
>> behaviour expected? It did surprise me. Below there is an example:
> [clip]
>
> It is expected. savez casts its input to arrays before saving.
If you actually want to save multiple arrays, you can use
savez('fname', *[a,b,c]) and they will be accessible under the names
arr_0, arr_1, etc. and a list of these names is in the 'files'
attribute on the NpzFile object. To retrieve your list of arrays when
you load, you can just do
mynewlist = [data[arrname] for arrname in data.files]
David
More information about the NumPy-Discussion
mailing list