[Numpy-discussion] Robust Sorting of Points

Pierre Haessig pierre.haessig at crans.org
Tue Oct 29 06:58:12 EDT 2013


Le 29/10/2013 11:37, Pierre Haessig a écrit :
> def compare(point, other):
>     delta = point - other
>     argmax = np.abs(delta).argmax()
>     delta_max = delta[argmax]
>     if delta_max > 0:
>         return 1
>     elif delta_max < 0:
>         return -1
>     else:
>         return 0
>
> This function returns a comparison of the coordinates with the  biggest
> absolute difference. Of course this doesn't define an *absolute order*
> (since it doesn't exist). But I think it defines a *relative order* (if
> this notion exists mathematically !!!!) which is indeed robust.
In fact this comparison is not robust for points whose difference has
two coordinates of almost same absolute magnitude but of different sign :

p1 = np.array([1,-1,0])
p2 = np.array([1,-1+1e-3,0])
p3 = np.array([1,-1-1e-3,0])

compare(p1,p1)
Out[26]: 0

compare(p1,p2)
Out[27]: -1

compare(p1,p3)
Out[28]: 1

sorry,
Pierre
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20131029/e17ce2df/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 900 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20131029/e17ce2df/attachment.sig>


More information about the NumPy-Discussion mailing list