Identifying the index of a repeated element in an array [message #94520] |
Tue, 20 June 2017 13:49  |
thtran296
Messages: 8 Registered: June 2017
|
Junior Member |
|
|
Hello everybody,
I have an array that looks like this:
x = [1,2,3,4,5,0,1,2,0,0,0,0,1,2,3,0,0,0,1,2,3]
I am interested in the location of the element "5" (index 4), "3" (index 14), and "3" (index 20).
I am writing a program to output the above three indices.
However, using min(where(x eq 3)) keeps giving me the index of the first 3, which I do not want.
I need the index of the second 3, and the third 3.
Is there any way to do this?
Thank you so much!
|
|
|
Re: Identifying the index of a repeated element in an array [message #94521 is a reply to message #94520] |
Tue, 20 June 2017 16:56  |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 6/20/17 2:49 pm, thtran296@gmail.com wrote:
> Hello everybody,
>
> I have an array that looks like this:
> x = [1,2,3,4,5,0,1,2,0,0,0,0,1,2,3,0,0,0,1,2,3]
> I am interested in the location of the element "5" (index 4), "3" (index 14), and "3" (index 20).
> I am writing a program to output the above three indices.
> However, using min(where(x eq 3)) keeps giving me the index of the first 3, which I do not want.
> I need the index of the second 3, and the third 3.
>
> Is there any way to do this?
>
> Thank you so much!
>
I'm not sure of your question. Here is the answer to your question as
stated:
ind = where(x eq 3)
print, ind[1], ind[2]
Is this what you need?
Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
|
|
|