array 'minus' [message #36090] |
Mon, 18 August 2003 20:00  |
tomson
Messages: 39 Registered: March 2003
|
Member |
|
|
Hi, I'd like to eliminate some elements in a array. For example,
A=[1,2,3,4,5,6,7,8,9,0]
N=[3,6]
I want to get a array b equal to A but without A(3) and A(6). How to do
that?
Thank you.
Tomson
|
|
|
Re: array 'minus' [message #36167 is a reply to message #36090] |
Tue, 19 August 2003 17:24   |
tomson
Messages: 39 Registered: March 2003
|
Member |
|
|
Thanks.
"tomson" <tom2959@21cn.com> д����Ϣ����:bhs3ot$1p1f$1@mail.cn99.com...
> Hi, I'd like to eliminate some elements in a array. For example,
> A=[1,2,3,4,5,6,7,8,9,0]
> N=[3,6]
> I want to get a array b equal to A but without A(3) and A(6). How to do
> that?
>
> Thank you.
>
> Tomson
>
>
|
|
|
Re: array 'minus' [message #36168 is a reply to message #36090] |
Tue, 19 August 2003 17:24   |
tomson
Messages: 39 Registered: March 2003
|
Member |
|
|
Thanks.
"tomson" <tom2959@21cn.com> д����Ϣ����:bhs3ot$1p1f$1@mail.cn99.com...
> Hi, I'd like to eliminate some elements in a array. For example,
> A=[1,2,3,4,5,6,7,8,9,0]
> N=[3,6]
> I want to get a array b equal to A but without A(3) and A(6). How to do
> that?
>
> Thank you.
>
> Tomson
>
>
|
|
|
Re: array 'minus' [message #36230 is a reply to message #36090] |
Thu, 28 August 2003 09:35  |
JD Smith
Messages: 850 Registered: December 1999
|
Senior Member |
|
|
On Mon, 18 Aug 2003 20:00:03 -0700, tomson wrote:
> Hi, I'd like to eliminate some elements in a array. For example,
> A=[1,2,3,4,5,6,7,8,9,0]
> N=[3,6]
> I want to get a array b equal to A but without A(3) and A(6). How to do
> that?
>
The HISTOGRAM solution is detailed in the tutorial on D. Fanning's site:
Problem: Remove some elements, listed in random order, from a vector.
IDL> vec=randomu(sd,10)
IDL> remove=[3,7,2,8]
IDL> keep=where(histogram(remove,MIN=0,MAX=n_elements(vec)-1) eq 0,cnt)
IDL> if cnt ne 0 then vec=vec[keep]
IDL> print,keep
0 1 4 5 6 9
We've used HISTOGRAM and WHERE to simply generate a list of kept indices.
This method will excel when you have lots of elements to remove, or any
repeated elements.
JD
|
|
|