<div dir="ltr"><div dir="ltr">On Thu, Jul 16, 2020 at 11:41 AM Roman Yurchak <<a href="mailto:rth.yurchak@gmail.com">rth.yurchak@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">One issue with adding a tolerance to np.unique for floats is say you have<br>
  [0, 0.1, 0.2, 0.3, 0.4, 0.5] with atol=0.15<br>
<br>
Should this return a single element or multiple ones? One once side each <br>
consecutive float is closer than the tolerance to the next one but the <br>
first one and the last one are clearly not within atol.<br>
<br>
Generally this is similar to what DBSCAN clustering algorithm does (e.g. <br>
in scikit-learn) and that would probably be out of scope for np.unique.<br></blockquote><div><br></div><div>I agree, I don't think there's an easy answer for selecting "approximately unique" floats in the case of overlap.</div><div><br></div><div>np.unique() does actually have well defined behavior for float, comparing floats for exact equality. This isn't always directly useful, but it definitely is well defined.</div><div><br></div><div>My suggestion for this use-case would be round floats to the desired precision before passing them into np.unique().</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Roman<br>
<br>
On 16/07/2020 20:27, Amin Sadeghi wrote:<br>
> It would be handy to add "atol" and "rtol" optional arguments to the <br>
> "unique" method. I'm proposing this since uniqueness is a bit vague for <br>
> floats. This change would be clearly backwards-compatible.<br>
> <br>
> _______________________________________________<br>
> NumPy-Discussion mailing list<br>
> <a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
> <br>
<br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div></div>