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

Home » Public Forums » archive » Re: arrays as subscripts
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: arrays as subscripts [message #30780] Fri, 17 May 2002 13:38
lyubo is currently offline  lyubo
Messages: 34
Registered: March 2002
Member
Thanks for your help!

Lyubo


"David Fanning" <david@dfanning.com> wrote in message
news:MPG.174e651d56947d449898e0@news.frii.com...
> Marshall Perrin (mperrin+news@arkham.berkeley.edu) writes:
>
>> He said a new array, though, for the last one, so something like
>>
>> newarr = fltarr(n_elements(B)) ; or whatever type of arr it is
>> I = Where(A GT 0, count)
>> IF count GT 0 THEN BEGIN
>> newarr[i] = c[b[i]]
>> ENDIF
>>
>> I think that's what he was getting at...
>
> Uh, right. I went a beer too far. :-(
>
> Cheshers,
>
> David
>
> --
> David W. Fanning, Ph.D.
> Fanning Software Consulting
> Phone: 970-221-0438, E-mail: david@dfanning.com
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
> Toll-Free IDL Book Orders: 1-888-461-0155
Re: arrays as subscripts [message #30792 is a reply to message #30780] Fri, 17 May 2002 07:52 Go to previous message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
"Marshall Perrin" <mperrin+news@arkham.berkeley.edu> wrote in message
news:ac1vi6$28r8$1@agate.berkeley.edu...
> David Fanning <david@dfanning.com> wrote:
>>
>> I = Where(A GT 0, count)
>> IF count GT 0 THEN BEGIN
>> bindex = b[i]
>> b[i] = c[bindex]
>> ENDIF
>
> He said a new array, though, for the last one, so something like
>
> newarr = fltarr(n_elements(B)) ; or whatever type of arr it is

A favorite trick of mine for making a cleared-out copy of an array (with the
same type) is:

newarr = Make_Array(Size=Size(B)) ; *whatever* type of arr it is!

Cheers,
--
-Dick

Dick Jackson / dick@d-jackson.com
D-Jackson Software Consulting / http://www.d-jackson.com
Calgary, Alberta, Canada / +1-403-242-7398 / Fax: 241-7392
Re: arrays as subscripts [message #30797 is a reply to message #30792] Fri, 17 May 2002 00:54 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Marshall Perrin (mperrin+news@arkham.berkeley.edu) writes:

> He said a new array, though, for the last one, so something like
>
> newarr = fltarr(n_elements(B)) ; or whatever type of arr it is
> I = Where(A GT 0, count)
> IF count GT 0 THEN BEGIN
> newarr[i] = c[b[i]]
> ENDIF
>
> I think that's what he was getting at...

Uh, right. I went a beer too far. :-(

Cheshers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
Re: arrays as subscripts [message #30803 is a reply to message #30797] Thu, 16 May 2002 21:05 Go to previous message
mperrin+news is currently offline  mperrin+news
Messages: 81
Registered: May 2001
Member
David Fanning <david@dfanning.com> wrote:
> lyubo (lzagorch@cs.wright.edu) writes:
>
>> Suppose I have 3 arrays with the same dimensions: A, B and C.
>>
>> I have to use the non zero elements of A as index to access B, then use
>> the accessed values from B as index to access C, and finally store the
>> values from C in a new array at the previously indexed positions of B.
>>
>> Is there an effective way to do that in IDL? I can write a call to a
>> C function but I was wondering if I can do it only in IDL.
>>
>> Any examples and help would be appreciated.
>
> I'm doing this after a couple of beers, so...
>
> I = Where(A GT 0, count)
> IF count GT 0 THEN BEGIN
> bindex = b[i]
> b[i] = c[bindex]
> ENDIF

He said a new array, though, for the last one, so something like

newarr = fltarr(n_elements(B)) ; or whatever type of arr it is
I = Where(A GT 0, count)
IF count GT 0 THEN BEGIN
newarr[i] = c[b[i]]
ENDIF

I think that's what he was getting at...

- Marshall
Re: arrays as subscripts [message #30804 is a reply to message #30803] Thu, 16 May 2002 20:39 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
lyubo (lzagorch@cs.wright.edu) writes:

> Suppose I have 3 arrays with the same dimensions: A, B and C.
>
> I have to use the non zero elements of A as index to access B, then use
> the accessed values from B as index to access C, and finally store the
> values from C in a new array at the previously indexed positions of B.
>
> Is there an effective way to do that in IDL? I can write a call to a
> C function but I was wondering if I can do it only in IDL.
>
> Any examples and help would be appreciated.

I'm doing this after a couple of beers, so...

I = Where(A GT 0, count)
IF count GT 0 THEN BEGIN
bindex = b[i]
b[i] = c[bindex]
ENDIF

Cheers,

David

--
David W. Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Digital maintenance handbook
Next Topic: Re: Digital maintenance handbook

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

Current Time: Fri Oct 10 08:19:53 PDT 2025

Total time taken to generate the page: 1.41402 seconds