<div dir="ltr">I can confirm, the issue seems to be in sorting:<div><br></div><div><div>>>> np.sort(V_)</div><div>array([([0.5, 0.0, 1.0],), ([0.5, 0.0, -1.0],), ([0.5, -0.0, 1.0],),</div><div>       ([0.5, -0.0, -1.0],)],</div>
<div>      dtype=[('v', '<f4', (3,))])</div></div><div><br></div><div>These I think are handled by the generic sort functions, and it looks like the comparison function being used is the one for a VOID dtype with no fields, so it is being done byte-wise, hence the problems with 0.0 and -0.0. Not sure where exactly the bug is, though...</div>
<div><br></div><div>Jaime</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Aug 22, 2014 at 6:20 AM, Nicolas P. Rougier <span dir="ltr"><<a href="mailto:Nicolas.Rougier@inria.fr" target="_blank">Nicolas.Rougier@inria.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>Hello,</div><div><br></div><div>I've found a strange behavior or I'm missing something obvious (or np.unique is not supposed to work with structured arrays).</div>
<div><br></div><div>I'm trying to extract unique values from a simple structured array but it does not seem to work as expected.</div><div>Here is a minimal script showing the problem:</div><div><br></div><div><font face="Menlo">import numpy as np<br>
<br>V = np.zeros(4, dtype=[("v", np.float32, 3)])<br>V["v"] = [ [0.5,    0.0,   1.0],<br>           [0.5, -1.e-16,  1.0], # [0.5, +1.e-16,  1.0] works<br>           [0.5,    0.0,  -1.0],<br>           [0.5, -1.e-16, -1.0]] # [0.5, +1.e-16, -1.0]] works<br>
V_ = np.zeros_like(V)<br>V_["v"][:,0] = V["v"][:,0].round(decimals=3)<br>V_["v"][:,1] = V["v"][:,1].round(decimals=3)<br>V_["v"][:,2] = V["v"][:,2].round(decimals=3)<br>
<br>print np.unique(V_)<br>[([0.5, 0.0, 1.0],) ([0.5, 0.0, -1.0],) ([0.5, -0.0, 1.0],) ([0.5, -0.0, -1.0],)]</font></div><div><br></div><div><br></div><div>While I would have expected:</div><div><div><font face="Menlo"><br>
</font></div><div><font face="Menlo">[([0.5, 0.0, 1.0],) ([0.5, 0.0, -1.0],)]</font></div></div><div><font face="Menlo"><br></font></div><div><font face="Menlo"><br></font></div><div><div>Can anyone confirm ?</div></div><span class="HOEnZb"><font color="#888888"><div>
<br></div><div><br></div><div>Nicolas</div></font></span></div><br>_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="http://mail.scipy.org/mailman/listinfo/numpy-discussion" target="_blank">http://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>(\__/)<br>( O.o)<br>( > <) Este es Conejo. Copia a Conejo en tu firma y ayúdale en sus planes de dominación mundial.
</div>