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

Home » Public Forums » archive » where on indices based on a variable condition without many loops
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
where on indices based on a variable condition without many loops [message #88287] Mon, 07 April 2014 15:28 Go to next message
havok2063 is currently offline  havok2063
Messages: 24
Registered: December 2012
Junior Member
I'm looking for a non-loop or single loop solution to the following problem. I need to select "good" indices of a 2d-array based on two conditions.

The original code was this

good = where(error NE 999 AND abs(diff) LT radius, ngood)

where error and diff are 2d-arrays of rough size 4000x700 and radius is a scalar = 2.0. this returned a reformed 1-d array of indices that satisfied the conditions of the where on the 2-d array.

Now I need to replace the scalar radius with an array of (not all) varying numbers, e.g. [2.0,2.0,3.0,2.0,4.0].
These new values reference certain subsets inside the row dimension [0:699] of the 2-d array, e.g. element 0 in radius applies to elements [*,0:31] in the 2-d array, element 1 applies to [*,32:60] , etc, etc. I do know what the indices are that mark these subsets.

I still need "good" to be a 1-d returned array of the correct indices in the full 2-d array satisfying the above conditions.

I've been testing various loop ideas that could work, but how do I remap the indices in the individual subsets returned in the loop iterations to the right indices in the full array?

I feel like the solution involves value_locate, histogram, and unique , but I haven't quite been able to converge.

Any ideas? Thanks.
Re: where on indices based on a variable condition without many loops [message #88288 is a reply to message #88287] Mon, 07 April 2014 19:28 Go to previous messageGo to next message
Heinz Stege is currently offline  Heinz Stege
Messages: 189
Registered: January 2003
Senior Member
Hi Brian,

if I got it right, you don't need any loop. You can work with an
4000x700 array for radius and use exactly the good=... line as in the
original code:

etc=[0,32,61,100,400]
ii=value_locate(etc,indgen(700))
radius_vs_row=([2.0,2.0,3.0,2.0,4.0])[ii]
radius=rebin(transpose(radius_vs_row),4000,700,/sample)
good = where(error NE 999 AND abs(diff) LT radius, ngood)

Cheers, Heinz
Re: where on indices based on a variable condition without many loops [message #88289 is a reply to message #88288] Mon, 07 April 2014 20:50 Go to previous message
havok2063 is currently offline  havok2063
Messages: 24
Registered: December 2012
Junior Member
Excellent. That did the trick and was exactly what I was looking for. Thanks a bunch.

Thanks, Brian


On Monday, April 7, 2014 10:28:04 PM UTC-4, Heinz Stege wrote:
> Hi Brian,
>
>
>
> if I got it right, you don't need any loop. You can work with an
>
> 4000x700 array for radius and use exactly the good=... line as in the
>
> original code:
>
>
>
> etc=[0,32,61,100,400]
>
> ii=value_locate(etc,indgen(700))
>
> radius_vs_row=([2.0,2.0,3.0,2.0,4.0])[ii]
>
> radius=rebin(transpose(radius_vs_row),4000,700,/sample)
>
> good = where(error NE 999 AND abs(diff) LT radius, ngood)
>
>
>
> Cheers, Heinz
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL 8.3 crash on workspace switch
Next Topic: ENVI/IDL vegetation identification

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

Current Time: Wed Oct 08 09:15:40 PDT 2025

Total time taken to generate the page: 0.00573 seconds