Re: simple question (I hope) [message #53251] |
Sun, 01 April 2007 10:23  |
William Daffer
Messages: 34 Registered: February 1999
|
Member |
|
|
"Ryan." <rchughes@brutus.uwaterloo.ca> writes:
> Dear All,
>
> Do any of you know a fast way of removing elements from an array given
> an array of the indices? I know it is possible with a FOR loop but I
> would like to avoid that if possbile because the array to be searched
> could get quite large. Here is an example of what I would like to do:
>
> A = [0,2,4,6,8,10,12,14,16,18,20]
> indices_to_remove = [3,5,9]
>
> to get a resulting array, B:
> B = [0,2,4,8,12,14,16,20]
IDL> A = [0,2,4,6,8,10,12,14,16,18,20]
IDL> indices_to_remove = [3,5,9]
IDL> Good = replicate(1,n_elements(a))
IDL> good[indices_to_remove]=0
IDL> good=where(good)
IDL> a=a[good]
IDL> print,a
0 2 4 8 12 14 16 20
IDL>
whd
--
OWE, v. To have (and to hold) a debt. The word formerly signified
not indebtedness, but possession; it meant "own," and in the minds of
debtors there is still a good deal of confusion between assets and
liabilities.
-- Ambrose Bierce: _The Devil's Dictionary_
|
|
|