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

Home » Public Forums » archive » Re: Extract Array positions for a set of Values
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Extract Array positions for a set of Values [message #75427 is a reply to message #75420] Wed, 09 March 2011 13:29 Go to previous messageGo to previous message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On Mar 9, 5:48 am, Paul Magdon <paulmag...@yahoo.de> wrote:
> Hi,
> have a quite simple problem for which I can find a fas solution:
>
> 1.) I have an IntArray A (e.g a result from LABEL_REGION)
>
> 1 1 1 1 0 0 0
> 1 1 1 1 0 0 2
> 0 0 0 0 9 0 2
>
> 2.) I have a vector B with Integers (e.g. 1,2,9)
>
> Now I want to extract the positions of B in A and set all values in A which are included in B to let's say 99. How can I do this without a loop?
> I tested HISTOGRAM(,REVERSE_INDICES) but as B is not consecutive (e.g 1,2,3,4) I can't find a solution.
>
> Cheers Paul

Here's a solution that uses a FOR-loop and histogram:

H = histogram(A,min=0,max=max(B),reverse_indices=ri)
for i=0,n_elements(B)-1 do begin
if H[B[i]] eq 0 then continue
A[ri[ri[B[i]]:ri[B[i]+1]-1]] = 99
endfor

Who cares if B isn't consecutive? Just use it to index the histogram
(and the reverse_indices array), so you only have to loop over B. I
would remove duplicate values, if any, from B beforehand to save
redundant iterations.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: LOADCT is not working
Next Topic: new COYOTE Graphics together with map_set

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

Current Time: Fri Oct 10 16:02:33 PDT 2025

Total time taken to generate the page: 2.00103 seconds