[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Filling an array



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. :-)

-- 
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155