<p dir="auto"><em>Original ticket <a href="http://projects.scipy.org/numpy/ticket/1176" rel="nofollow">http://projects.scipy.org/numpy/ticket/1176</a> on 2009-07-17 by trac user mauro, assigned to unknown.</em></p>
<p dir="auto">When making a deepcopy of a numpy.ndarray with dtype S a numpy.string_ is created.</p>
<p dir="auto">I am not too familiar with the numpy types, but I think they are basically the same. However, they have different <strong>repr</strong> and this can make this somewhat confusing (it confused me).</p>
<p dir="auto">I cite Chris Baker's message from numpy discussion, since I encountered the exact same bug and I could not find it reporter here:</p>
<p dir="auto">Hi folks,</p>
<p dir="auto">In [264]: np.<strong>version</strong><br>
Out[264]: '1.7.0'</p>
<p dir="auto">I just noticed that deep copying a rank-zero array yields a scalar --<br>
probably not what we want.</p>
<p dir="auto">In [242]: a1 = np.array(3)</p>
<p dir="auto">In [243]: type(a1), a1<br>
Out[243]: (numpy.ndarray, array(3))</p>
<p dir="auto">In [244]: a2 = copy.deepcopy(a1)</p>
<p dir="auto">In [245]: type(a2), a2<br>
Out[245]: (numpy.int32, 3)</p>
<p dir="auto">regular copy.copy() seems to work fine:</p>
<p dir="auto">In [246]: a3 = copy.copy(a1)</p>
<p dir="auto">In [247]: type(a3), a3<br>
Out[247]: (numpy.ndarray, array(3))</p>
<p dir="auto">Higher-rank arrays seem to work fine:</p>
<p dir="auto">In [253]: a1 = np.array((3,4))</p>
<p dir="auto">In [254]: type(a1), a1<br>
Out[254]: (numpy.ndarray, array([3, 4]))</p>
<p dir="auto">In [255]: a2 = copy.deepcopy(a1)</p>
<p dir="auto">In [256]: type(a2), a2<br>
Out[256]: (numpy.ndarray, array([3, 4]))</p>
<p dir="auto">Array scalars seem to work fine as well:</p>
<p dir="auto">In [257]: s1 = np.float32(3)</p>
<p dir="auto">In [258]: s2 = copy.deepcopy(s1)</p>
<p dir="auto">In [261]: type(s1), s1<br>
Out[261]: (numpy.float32, 3.0)</p>
<p dir="auto">In [262]: type(s2), s2<br>
Out[262]: (numpy.float32, 3.0)</p>
<p dir="auto">There are other ways to copy arrays, but in this case, I had a dict<br>
with a bunch of arrays in it, and needed a deepcopy of the dict. I was<br>
surprised to find that my rank-0 array got turned into a scalar.</p>