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

Home » Public Forums » archive » Re: Writing an efficient array operation in IDL
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
Re: Writing an efficient array operation in IDL [message #74823] Thu, 03 February 2011 05:45
Axel Martínez is currently offline  Axel Martínez
Messages: 22
Registered: June 2010
Junior Member
On Feb 3, 2:14 am, Rony K Varghese <ronykvargh...@gmail.com> wrote:
> Dear ALL,
>
> Suppose, I have to create an output array B filled with value 8 as
> follows, from the input 5x5 array A.
>
> A  = 0 0 4 0 0
>        0 4 0 4 0
>        4 0 0 0 4
>        0 4 0 4 0
>        0 0 4 0 0
>
> B =  0 0 8 0 0
>        0 8 8 8 0
>        8 8 8 8 8
>        0 8 8 8 0
>        0 0 8 0 0
>
> The logic is to fill the whole region bounded by value 4 in the input
> array, with the value 8 in the output array.
> How i can do this efficiently in IDL, like using array operations?
> I need to apply for a large sized array.
> Thanks in advance..
>
> - Rony

Hi,

Check the IDL function LABEL_REGION, this should do it.
Re: Writing an efficient array operation in IDL [message #74837 is a reply to message #74823] Wed, 02 February 2011 19:37 Go to previous message
Ammar Yusuf is currently offline  Ammar Yusuf
Messages: 36
Registered: October 2010
Member
On Feb 2, 8:14 pm, Rony K Varghese <ronykvargh...@gmail.com> wrote:
> Dear ALL,
>
> Suppose, I have to create an output array B filled with value 8 as
> follows, from the input 5x5 array A.
>
> A  = 0 0 4 0 0
>        0 4 0 4 0
>        4 0 0 0 4
>        0 4 0 4 0
>        0 0 4 0 0
>
> B =  0 0 8 0 0
>        0 8 8 8 0
>        8 8 8 8 8
>        0 8 8 8 0
>        0 0 8 0 0
>
> The logic is to fill the whole region bounded by value 4 in the input
> array, with the value 8 in the output array.
> How i can do this efficiently in IDL, like using array operations?
> I need to apply for a large sized array.
> Thanks in advance..
>
> - Rony

So what you're doing is going through each row and finding the first 4
and replacing it with 8 until you hit the next four right?

I really can't think anything that will do it one vectorized call but
you can try this I guess.

for each row
use temp = where(to find all elements gt 0 or eq 4)
for that row arr[i,*] do this
if n_elements(temp) eq 1 then arr[i,temp] = 8
arr[i,temp[i]:temp[n_elements(temp-1)] = 8
go to next row.
endfor

I think that might work if you understand it. I would try it but I
don't have IDL the computer I'm using.

The other pseudocode algorithm I thought of but will definitely be
slower is this:

Make a double for loop and for each row find the first index and after
you find
that then start from the back of the row and find the last index. Use
some logic there
when the case is you only have one element in the row. Use those two
indicies to
replace the values.

Hope that helps.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Library/Functions to write configuration file for application
Next Topic: IDL 8 image function

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

Current Time: Wed Oct 08 13:48:23 PDT 2025

Total time taken to generate the page: 0.00521 seconds