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

Home » Public Forums » archive » Re: newbie question on array manipulation
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: newbie question on array manipulation [message #66283] Tue, 05 May 2009 23:54
jpardila is currently offline  jpardila
Messages: 2
Registered: May 2009
Junior Member
Thank you so much for your help Jean and Ben. The link on histogram is
very good. I follow the tutorial and yes it can be quite handy. For
now I just used the where statement as I only have to change a few
values. I am happy to finally find out this here as I always used so
far the Raster Calculator in ArcGis when doing raster operations. Now
to completely close the gap I wonder if those operations can also be
done effectively to model relationships between different layers which
are georreferenced and overlap each other (they come from ENVI) but
might cover different extents. Something like if in arrayA[a] = 5 then
arrayB= 100. This is based purely on the geographic location of pixels
(x,y coordinates). I hope it is clear what I mean.
Next cup of coffee is on me!! Cheers,
JP
Re: newbie question on array manipulation [message #66285 is a reply to message #66283] Tue, 05 May 2009 06:24 Go to previous message
ben.bighair is currently offline  ben.bighair
Messages: 221
Registered: April 2007
Senior Member
On May 5, 7:53 am, "ben.bighair" <ben.bigh...@gmail.com> wrote:
> On May 5, 7:40 am, jpardila <blu...@gmail.com> wrote:
>
>> What is the best way to manipulate one array and remap its values
>> according to conditions?
>> Let's say I have a 2-d array, for all the elements equal to 5 I want
>> to change their values to 0. For values equal to 10 I want to convert
>> to 1 and so on. I am really confused and don't know if to use IF,
>> where, for or while. Thanks for answering this basic one.
>> JP
>
> Hi,
>
> The simplest is to use where - don't forget to use the output COUNT
> argument shown here as "na".
>
> a = WHERE(array EQ 10, na)
> if (na GT 0) then array[a] = 1
>
> If you are doing a multiple replacements (of different values) in a
> single array then you'll want to strap your sneakers on and use
> HISTOGRAM with it's REVERSE_INDICES output keyword. Seehttp://dfanning.com/tips/histogram_tutorial.htmlfor more on that - it
> is the swiss knife of IDL.
>

Hi again,

Another thought after a cup of coffee... if your application uses
floating point values instead of integers then you should search this
news group for info on how to test for equality with floats (single or
double precision).

Cheers (again),
Ben
Re: newbie question on array manipulation [message #66287 is a reply to message #66285] Tue, 05 May 2009 06:06 Go to previous message
Jean H. is currently offline  Jean H.
Messages: 472
Registered: July 2006
Senior Member
ben.bighair wrote:
> On May 5, 7:40 am, jpardila <blu...@gmail.com> wrote:
>> What is the best way to manipulate one array and remap its values
>> according to conditions?
>> Let's say I have a 2-d array, for all the elements equal to 5 I want
>> to change their values to 0. For values equal to 10 I want to convert
>> to 1 and so on. I am really confused and don't know if to use IF,
>> where, for or while. Thanks for answering this basic one.
>> JP
>
> Hi,
>
> The simplest is to use where - don't forget to use the output COUNT
> argument shown here as "na".
>
> a = WHERE(array EQ 10, na)
> if (na GT 0) then array[a] = 1


Also, if you have several values to changes, you can create a new array.
For example, if you want to change 5 -> 0 and 0 -> 10, but you don't
want to change the old 5 to 10!

copy = array ;copy the array
a = WHERE(array EQ 10, na)
if (na GT 0) then copy[a] = 1

Jean
Re: newbie question on array manipulation [message #66290 is a reply to message #66287] Tue, 05 May 2009 04:53 Go to previous message
ben.bighair is currently offline  ben.bighair
Messages: 221
Registered: April 2007
Senior Member
On May 5, 7:40 am, jpardila <blu...@gmail.com> wrote:
> What is the best way to manipulate one array and remap its values
> according to conditions?
> Let's say I have a 2-d array, for all the elements equal to 5 I want
> to change their values to 0. For values equal to 10 I want to convert
> to 1 and so on. I am really confused and don't know if to use IF,
> where, for or while. Thanks for answering this basic one.
> JP

Hi,

The simplest is to use where - don't forget to use the output COUNT
argument shown here as "na".

a = WHERE(array EQ 10, na)
if (na GT 0) then array[a] = 1

If you are doing a multiple replacements (of different values) in a
single array then you'll want to strap your sneakers on and use
HISTOGRAM with it's REVERSE_INDICES output keyword. See
http://dfanning.com/tips/histogram_tutorial.html for more on that - it
is the swiss knife of IDL.

CHeers,
Ben
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: newbie question on array manipulation
Next Topic: Trying to run ENVI_FX_DOIT example

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

Current Time: Wed Oct 08 13:47:45 PDT 2025

Total time taken to generate the page: 0.00674 seconds