comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » rebinning two arrays? or re: finding exclusive elements between 2 not-quite identical arrays?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
rebinning two arrays? or re: finding exclusive elements between 2 not-quite identical arrays? [message #89750] Fri, 28 November 2014 08:54 Go to next message
havok2063 is currently offline  havok2063
Messages: 24
Registered: December 2012
Junior Member
So this post is related to my original post here, but it's not quite working out.
https://groups.google.com/forum/#!topic/comp.lang.idl-pvwave /CtiGTuNqD10

...

So I have two arrays where I need to extract the elements in one array not in the other, but the elements are not quite exact to one another.

A = [309, 313, 318, 322, 327, 331, 336, 340]
B = [305, 309, 314, 318, 323, 327, 332, 336, 341, 345]

B is the true array, and A is the "found" array that is missing some elements. I want to find all elements missing from A that exist in B.

The solution I adopted, from the previous post, is something like

diff = 2 ; offset between integers
temp = value_locate(A,B)
missloc = where(B-A[temp] gt diff and A[temp+1]-B gt diff, misscount)

This mostly works, however it does not work when the elements that are missing are the edges, i.e. the first or last element.

I can't seem to get value_locate to chunk the two together the way I want. Is there a way to rebin A so that the elements in A that are the same match those in B, e.g. 309=309, 313 changes to 314, 322 changes to 323, etc? So the elements match up, so then I could do a simple thing like this

missloc = where(histogram(A, omin=om) eq 0 and histogram(B, min=om) ne 0) + om

However, I tested this out by forcing the like elements to be the same, and this also does not work when the missing elements are the first and last elements. It only seems to work when the missing elements are internal, i.e when there is at least 1 common element first.

Any suggestions on a more robust solution for either problem?

Thanks, Brian
Re: rebinning two arrays? or re: finding exclusive elements between 2 not-quite identical arrays? [message #89751 is a reply to message #89750] Fri, 28 November 2014 10:49 Go to previous messageGo to next message
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
Hi Brian.

On Fri, 28 Nov 2014 08:54:10 -0800 (PST), Brian Cherinka wrote:

>
> So this post is related to my original post here, but it's not quite working out.
> https://groups.google.com/forum/#!topic/comp.lang.idl-pvwave /CtiGTuNqD10
>
> ...
>
> So I have two arrays where I need to extract the elements in one array not in the other, but the elements are not quite exact to one another.
>
> A = [309, 313, 318, 322, 327, 331, 336, 340]
> B = [305, 309, 314, 318, 323, 327, 332, 336, 341, 345]
>
> B is the true array, and A is the "found" array that is missing some elements. I want to find all elements missing from A that exist in B.
>
> The solution I adopted, from the previous post, is something like
>
> diff = 2 ; offset between integers
> temp = value_locate(A,B)
> missloc = where(B-A[temp] gt diff and A[temp+1]-B gt diff, misscount)
>
> This mostly works, however it does not work when the elements that are missing are the edges, i.e. the first or last element.
>
> [...]

The missing elements on the left edge were recognized by the
additional two lines in my draft. But not the missing elements on the
right edge. This is true.

However I would not use the histogram function to overcome this. I
would go a more easy way, which I expect to be both, faster and less
memory consuming. It is only a little change to the code above:

A = [309, 313, 318, 322, 327, 331, 336, 340]
B = [305, 309, 314, 318, 323, 327, 332, 336, 341, 345]
diff = 2 ; offset between integers
temp = value_locate(A,B)
missloc = where((B-A[temp] gt diff and A[temp+1]-B gt diff) or $
a[0]-b gt diff or $ ; elements on the left edge
b-a[n_elements(a)-1] gt diff, $ ; right edge
misscount)
if misscount ge 1 then print,b[missloc]

Good luck again, Heinz
Re: rebinning two arrays? or re: finding exclusive elements between 2 not-quite identical arrays? [message #89752 is a reply to message #89751] Fri, 28 November 2014 11:05 Go to previous message
havok2063 is currently offline  havok2063
Messages: 24
Registered: December 2012
Junior Member
Hi Heinz,

Thanks so much. That's perfect. Sorry I missed that other line in your original post. Thanks for pointing it out. Things make much more sense now. Thanks for your help.

Cheers, Brian

On Friday, November 28, 2014 1:49:23 PM UTC-5, Heinz Stege wrote:
> Hi Brian.
>
> On Fri, 28 Nov 2014 08:54:10 -0800 (PST), Brian Cherinka wrote:
>
>>
>> So this post is related to my original post here, but it's not quite working out.
>> https://groups.google.com/forum/#!topic/comp.lang.idl-pvwave /CtiGTuNqD10
>>
>> ...
>>
>> So I have two arrays where I need to extract the elements in one array not in the other, but the elements are not quite exact to one another.
>>
>> A = [309, 313, 318, 322, 327, 331, 336, 340]
>> B = [305, 309, 314, 318, 323, 327, 332, 336, 341, 345]
>>
>> B is the true array, and A is the "found" array that is missing some elements. I want to find all elements missing from A that exist in B.
>>
>> The solution I adopted, from the previous post, is something like
>>
>> diff = 2 ; offset between integers
>> temp = value_locate(A,B)
>> missloc = where(B-A[temp] gt diff and A[temp+1]-B gt diff, misscount)
>>
>> This mostly works, however it does not work when the elements that are missing are the edges, i.e. the first or last element.
>>
>> [...]
>
> The missing elements on the left edge were recognized by the
> additional two lines in my draft. But not the missing elements on the
> right edge. This is true.
>
> However I would not use the histogram function to overcome this. I
> would go a more easy way, which I expect to be both, faster and less
> memory consuming. It is only a little change to the code above:
>
> A = [309, 313, 318, 322, 327, 331, 336, 340]
> B = [305, 309, 314, 318, 323, 327, 332, 336, 341, 345]
> diff = 2 ; offset between integers
> temp = value_locate(A,B)
> missloc = where((B-A[temp] gt diff and A[temp+1]-B gt diff) or $
> a[0]-b gt diff or $ ; elements on the left edge
> b-a[n_elements(a)-1] gt diff, $ ; right edge
> misscount)
> if misscount ge 1 then print,b[missloc]
>
> Good luck again, Heinz
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: cgimage/overlaid grid
Next Topic: Confusion about nthread and ncore

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 07:17:27 PDT 2025

Total time taken to generate the page: 0.00454 seconds