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

Home » Public Forums » archive » Re: Filling an array
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: Filling an array [message #23284 is a reply to message #23278] Wed, 17 January 2001 21:37 Go to previous messageGo to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
davidf@dfanning.com (David Fanning) writes:

> Pavel A. Romashkin (pavel.romashkin@noaa.gov) writes:
>
>> If I have
>>
>> a = findgen(10)
>> b = fix(100* randomu(10, 10))
>> ; N_elements(a) is equal to n_elements(b)
>> c = findgen(total(b))
>>
>> how can I fill C with values from A using B as a running index, so that
>>
>> c[0 : b[0]-1] = a[0]
>> c[b[0] : b[0]+b[1]-1] = a[1]
>>
>> etc, without looping through "n_elements(b)-1" iterations?
>> I have a fast solution with a loop and indexing using total(/cumulative)
>> and a very slow one with loop and replicate, but I can't come up with a
>> loop-free one.
>
> Totally impossible. :-(
>
> Cheers,
>
> P.S. Let's just say that usually gets the juices going
> on the usual suspects, and I figured you could use the
> help. :-)

Juices or not, I don't see how this can be done without a loop. Since
the segments specified by B can be of different sizes, I think you are
stuck. However, as I've said in the past: loops aren't bad! If you
can get enough work done in a single iteration then loops are fine.

Craig

--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: TeXtoIDL is back, and updated!
Next Topic: Re: Speaking of .wav files...

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

Current Time: Sat Oct 11 16:08:09 PDT 2025

Total time taken to generate the page: 1.87509 seconds