howto exclude elements from sorted array which are present in other sorted array
hi all, I have 2 sorted arrays arr1 & arr2 (ascending order, for example [1,2,5,8] and [3,5], but length may be thousands, so I need simpliest way, not costly). Howto obtain arr3 that consists of elements present in arr1 but absent in arr2? Of course, I can write something by myself, like arr3 = [x for x in arr1 if not x in arr2] but maybe already written routines are present in numpy? (that use sort)
Usually arr2 is much more small than arr1, typical former size is 1020 and typical latter size can be 100010000
Thank you in advance, D.
thanks all, I have solved the problem dmitrey wrote:
hi all, I have 2 sorted arrays arr1 & arr2 (ascending order, for example [1,2,5,8] and [3,5], but length may be thousands, so I need simpliest way, not costly). Howto obtain arr3 that consists of elements present in arr1 but absent in arr2? Of course, I can write something by myself, like arr3 = [x for x in arr1 if not x in arr2] but maybe already written routines are present in numpy? (that use sort)
Usually arr2 is much more small than arr1, typical former size is 1020 and typical latter size can be 100010000
Thank you in advance, D. _______________________________________________ Numpydiscussion mailing list Numpydiscussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpydiscussion
On 5/29/07, dmitrey openopt@ukr.net wrote:
hi all, I have 2 sorted arrays arr1 & arr2 (ascending order, for example [1,2,5,8] and [3,5], but length may be thousands, so I need simpliest way, not costly). Howto obtain arr3 that consists of elements present in arr1 but absent in arr2? Of course, I can write something by myself, like arr3 = [x for x in arr1 if not x in arr2] but maybe already written routines are present in numpy? (that use sort)
Usually arr2 is much more small than arr1, typical former size is 1020 and typical latter size can be 100010000
count = arr2.searchsorted(arr1, side='right')  arr2.searchsorted(arr1, side='left') arr3 = arr1[count == 0]
Chuck
participants (2)

Charles R Harris

dmitrey