Python : save dictionaries through numpy.save
<p>I have a large data set (millions of rows) in memory, in the form of <strong>numpy arrays</strong> and <strong>dictionaries</strong>. </p>

<p>Once this data is constructed I want to store them into files; 
so, later I can load these files into memory quickly, without reconstructing this data from the scratch once again.</p>

<p><strong>np.save</strong> and <strong>np.load</strong> functions does the job smoothly for numpy arrays.<br>
But I am facing problems with dict objects. </p>

<p>See below sample. d2 is the dictionary which was loaded from the file. <strong>See #out[28] it has been loaded into d2 as a numpy array, not as a dict.</strong> So further dict operations such as get are not working.</p>

<p>Is there a way to load the data from the file as dict (instead of numpy array) ?</p>

<pre><code>In [25]: d1={'key1':[5,10], 'key2':[50,100]}

In [26]: np.save("d1.npy", d1)

In [27]: d2=np.load("d1.npy")

In [28]: d2
Out[28]: array({'key2': [50, 100], 'key1': [5, 10]}, dtype=object)

In [30]: d1.get('key1')  #original dict before saving into file
Out[30]: [5, 10]

In [31]: d2.get('key2')  #dictionary loaded from the file
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
&lt;ipython-input-31-23e02e45bf22&gt; in &lt;module&gt;()
----&gt; 1 d2.get('key2')

AttributeError: 'numpy.ndarray' object has no attribute 'get'
</code></pre>