[Numpy-discussion] np.unique with structured arrays
Eelco Hoogendoorn
hoogendoorn.eelco at gmail.com
Fri Aug 22 10:52:07 EDT 2014
It does not sound like an issue with unique, but rather like a matter of floating point equality and representation. Do the ' identical' elements pass an equality test?
-----Original Message-----
From: "Nicolas P. Rougier" <Nicolas.Rougier at inria.fr>
Sent: 22-8-2014 15:21
To: "Discussion of Numerical Python" <numpy-discussion at scipy.org>
Subject: [Numpy-discussion] np.unique with structured arrays
Hello,
I've found a strange behavior or I'm missing something obvious (or np.unique is not supposed to work with structured arrays).
I'm trying to extract unique values from a simple structured array but it does not seem to work as expected.
Here is a minimal script showing the problem:
import numpy as np
V = np.zeros(4, dtype=[("v", np.float32, 3)])
V["v"] = [ [0.5, 0.0, 1.0],
[0.5, -1.e-16, 1.0], # [0.5, +1.e-16, 1.0] works
[0.5, 0.0, -1.0],
[0.5, -1.e-16, -1.0]] # [0.5, +1.e-16, -1.0]] works
V_ = np.zeros_like(V)
V_["v"][:,0] = V["v"][:,0].round(decimals=3)
V_["v"][:,1] = V["v"][:,1].round(decimals=3)
V_["v"][:,2] = V["v"][:,2].round(decimals=3)
print np.unique(V_)
[([0.5, 0.0, 1.0],) ([0.5, 0.0, -1.0],) ([0.5, -0.0, 1.0],) ([0.5, -0.0, -1.0],)]
While I would have expected:
[([0.5, 0.0, 1.0],) ([0.5, 0.0, -1.0],)]
Can anyone confirm ?
Nicolas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20140822/a488d91f/attachment.html>
More information about the NumPy-Discussion
mailing list