1 Sep 2009 14:07
Question about np.savez
<jorgesmbox-ml <at> yahoo.es>
2009-09-01 12:07:36 GMT
2009-09-01 12:07:36 GMT
Hi,
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:
In [18]: l
Out[18]:
[array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
array([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18]),
array([ 0, 3, 6, 9, 12, 15, 18, 21, 24, 27])]
In [19]: np.savez('test.npz', l=l)
In [20]: data = np.load('test.npz')
In [21]: l1 = data['l']
In [22]: l1
Out[22]:
array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
[ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18],
[ 0, 3, 6, 9, 12, 15, 18, 21, 24, 27]])
jorge
RSS Feed