Re: indexing arrays with arrays [message #55203 is a reply to message #2442] |
Tue, 07 August 2007 12:25  |
GeoffS
Messages: 1 Registered: August 2007
|
Junior Member |
|
|
The only way I know to do that is using an "array of indices" to index
into the source array. For example, the answer to your specific
problem would be to create an array containing:
indexes = [0,1, 1,2, 2,3, 3,4, 4,5]
then the extraction statement is simply:
extract = res[indexes]
The extraction statement should be pretty efficient as it uses
implicit loops inside the IDL interpreter/VM. If you need to extract
the same elements many times, then this would be a reasonable
solution, but if you need an efficient/loopless way to create the
'indexes' array then it probably won't help you.
Cheers,
Geoff S.
On Aug 7, 8:39 am, Conor <cmanc...@gmail.com> wrote:
> It seems to me that a highly useful syntax for IDL would be something
> like this:
>
> res = randomu(seed,10)
> start_ind = indgen(5)
> end_ind = start_ind + 1
>
> extract = res[start_ind:end_ind]
>
> In this case, I would envision extract being a 10 element array.
> Namely, it would be the equivelent of:
>
> extract = [res[start_ind[0]:end_ind[0]], res[start_ind[1]:end_ind[1]],
> res[start_ind[2]:end_ind[2]], etc...]
|
|
|