<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Sep 5, 2013 at 12:35 PM, Jonathan Helmus <span dir="ltr"><<a href="mailto:jjhelmus@gmail.com" target="_blank">jjhelmus@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF"><div class="im">
<div>On 09/05/2013 01:29 PM, Warren
Weckesser wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr"><br>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Thu, Sep 5, 2013 at 2:11 PM,
Fernando Perez <span dir="ltr"><<a href="mailto:fperez.net@gmail.com" target="_blank">fperez.net@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all,<br>
<br>
I just ran into this rather weird behavior:<br>
<br>
<a href="http://nbviewer.ipython.org/6453869" target="_blank">http://nbviewer.ipython.org/6453869</a><br>
<br>
In summary, as far as I can tell, shuffle is misbehaving
when acting<br>
on arrays that have structured dtypes. I've seen the
problem on 1.7.1<br>
(official on ubuntu 13.04) as well as master as of a few
minutes ago.<br>
<br>
Is this my misuse? It really looks like a bug to me...<br>
<br>
</blockquote>
<div><br>
<br>
</div>
<div>Definitely a bug:<br>
<br>
<span style="font-family:courier new,monospace">In [1]:
np.__version__<br>
Out[1]: '1.9.0.dev-573b3b0'<br>
<br>
In [2]: z = np.array([(0,),(1,),(2,),(3,),(4,)],
dtype=[('a',int)])<br>
<br>
In [3]: z<br>
Out[3]: <br>
array([(0,), (1,), (2,), (3,), (4,)], <br>
dtype=[('a', '<i8')])<br>
<br>
In [4]: shuffle(z)<br>
<br>
In [5]: z<br>
Out[5]: <br>
array([(0,), (1,), (2,), (0,), (0,)], <br>
dtype=[('a', '<i8')])</span><br>
<br>
<br>
<br>
</div>
<div>Nothing in the docstring suggests that it shouldn't
work for structured dtypes.<br>
<br>
Warren<br>
</div>
</div>
</div>
</div>
</blockquote>
<br></div>
Looks to stemming from the fact that elements of records arrays
cannot be swapped:<br>
<br>
In [1]: import numpy as np<br>
<br>
In [2]: x = np.zeros(5, dtype=[('n', 'S1'), ('i', int)])<br>
<br>
In [3]: x['i'] = range(5)<br>
<br>
In [4]: print x<div class="im"><br>
[('', 0) ('', 1) ('', 2) ('', 3) ('', 4)]<br>
<br></div>
In [5]: x[0], x[1] = x[1], x[0]<br>
<br>
In [6]: print x<div class="im"><br>
[('', 1) ('', 1) ('', 2) ('', 3) ('', 4)]<br>
<br></div>
This is with numpy 1.7.1<br>
<br></div></blockquote><div><br></div><div>Oh, nice one ;) Should be fixable if you want to submit a patch.<br><br></div><div>Chuck <br></div><br></div></div></div>