[Numpy-tickets] [NumPy] #410: setmember1d problem
NumPy
numpy-tickets at scipy.net
Sun Jan 7 23:20:37 CST 2007
#410: setmember1d problem
------------------------+---------------------------------------------------
Reporter: curiousjan | Owner: somebody
Type: defect | Status: closed
Priority: normal | Milestone:
Component: Other | Version:
Severity: normal | Resolution: fixed
Keywords: |
------------------------+---------------------------------------------------
Changes (by rkern):
* status: new => closed
* resolution: => fixed
Old description:
> Please see the attached scripts.
> I am simply comparing two arrays, storing items that appear in both
> lists.
> I do this by
> a) storing all items from list 1 that are also in list 2
> b) storing all items from list 2 that are also in list 1
> The two resulting arrays should be identical, but they are not.
> A simple fix is
>
> svn diff numpy/lib
> Index: numpy/lib/arraysetops.py
> ===================================================================
> --- numpy/lib/arraysetops.py (revision 3491)
> +++ numpy/lib/arraysetops.py (working copy)
> @@ -126,7 +126,7 @@
> zlike = nm.zeros_like
> ar = nm.concatenate( (ar1, ar2 ) )
> tt = nm.concatenate( (zlike( ar1 ), zlike( ar2 ) + 1) )
> - perm = ar.argsort()
> + perm = ar.argsort(kind='mergesort')
> aux = ar[perm]
> aux2 = tt[perm]
> # flag = ediff1d( aux, 1 ) == 0
New description:
Please see the attached scripts.
I am simply comparing two arrays, storing items that appear in both lists.
I do this by
a) storing all items from list 1 that are also in list 2
b) storing all items from list 2 that are also in list 1
The two resulting arrays should be identical, but they are not.
A simple fix is
svn diff numpy/lib
{{{
Index: numpy/lib/arraysetops.py
===================================================================
--- numpy/lib/arraysetops.py (revision 3491)
+++ numpy/lib/arraysetops.py (working copy)
@@ -126,7 +126,7 @@
zlike = nm.zeros_like
ar = nm.concatenate( (ar1, ar2 ) )
tt = nm.concatenate( (zlike( ar1 ), zlike( ar2 ) + 1) )
- perm = ar.argsort()
+ perm = ar.argsort(kind='mergesort')
aux = ar[perm]
aux2 = tt[perm]
# flag = ediff1d( aux, 1 ) == 0
}}}
Comment:
Well, I'm applying your change anyways. It seems to me like a stable sort
actually is required even if unique elements are provided. Good catch.
--
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/410#comment:4>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list