Finding values in an array [message #25476] |
Sun, 24 June 2001 21:26  |
Bob Fugate
Messages: 18 Registered: March 2001
|
Junior Member |
|
|
I have a vector containing a very, very large number of long integer values.
I want to compare the value of each element in the vector to the values of
the elements in the first column of a two column array until there is a
match, and then extract the corresponding number in the second column (e.g.
by using WHERE) of the array.
Does anyone know a way to do this without using a loop? I realise that
organizing the searched array as two rows may speed this up, however, I am
trying to avoid using a loop. The numbers in the vector vary randomly (and
it is important to preserve the original order) but the numbers in the first
column of the array are sorted and increase monotonically (if that matters).
I am new to IDL, so will greatly appreciate any suggestions.
Bob Fugate
|
|
|
Re: Finding values in an array [message #25562 is a reply to message #25476] |
Mon, 25 June 2001 20:59  |
david[2]
Messages: 100 Registered: June 2001
|
Senior Member |
|
|
Craig Markwardt writes:
> The German contingent completely drank me under the table. I'm not
> sure I said *anything* intelligible on the car ride back to the hotel.
> Then again, "unintelligible" is a valid IDL programming style, one
> that I practice often. :-)
Was that German those guys at the end were speaking!?
I thought I had accidentally stumbled into the Fun
with Histograms lecture. :-(
Cheers,
David
--
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
|
|
|
Re: Finding values in an array [message #25564 is a reply to message #25476] |
Mon, 25 June 2001 20:26  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
david@dfanning.com (David Fanning) writes:
> P.S. Let's just say a few of the drivers earned BIG
> money from the programming tips (or whatever)
> they heard in their cars last year.
The German contingent completely drank me under the table. I'm not
sure I said *anything* intelligible on the car ride back to the hotel.
Then again, "unintelligible" is a valid IDL programming style, one
that I practice often. :-)
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: Finding values in an array [message #25565 is a reply to message #25476] |
Mon, 25 June 2001 19:28  |
david[2]
Messages: 100 Registered: June 2001
|
Senior Member |
|
|
Bob Fugate writes:
> Hope I don't wear out my welcome by asking
> all the time and never feeling like I can contribute.
Oh, you'll get to contribute. We are looking for
volunteers right now for the Hospitality Committee
for the IDL Expert Programmers Association meeting
coming up in October. We especially need designated
drivers for the Commencement program.
Cheers,
David
P.S. Let's just say a few of the drivers earned BIG
money from the programming tips (or whatever)
they heard in their cars last year.
--
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
|
|
|
Re: Finding values in an array [message #25567 is a reply to message #25476] |
Mon, 25 June 2001 18:50  |
Bob Fugate
Messages: 18 Registered: March 2001
|
Junior Member |
|
|
Craig,
Thanks. value_locate is a miracle. I was using an old handi-guide that
didn't have this function listed, and since I am new to IDL, didn't know
about it. It works very well for what I am doing and is about a zillion
times faster than the terrible routine I wrote.
I really appreciate this group. Hope I don't wear out my welcome by asking
all the time and never feeling like I can contribute.
Bob
> From: Craig Markwardt <craigmnet@cow.physics.wisc.edu>
> Organization: U. Wisc. Madison Physics -- Compact Objects
> Reply-To: craigmnet@cow.physics.wisc.edu
> Newsgroups: comp.lang.idl-pvwave
> Date: 25 Jun 2001 01:18:59 -0500
> Subject: Re: Finding values in an array
>
>
> Bob Fugate <rqfugate@mindspring.com> writes:
>
>> I have a vector containing a very, very large number of long integer values.
>>
>> I want to compare the value of each element in the vector to the values of
>> the elements in the first column of a two column array until there is a
>> match, and then extract the corresponding number in the second column (e.g.
>> by using WHERE) of the array.
>>
>> Does anyone know a way to do this without using a loop? I realise that
>> organizing the searched array as two rows may speed this up, however, I am
>> trying to avoid using a loop. The numbers in the vector vary randomly (and
>> it is important to preserve the original order) but the numbers in the first
>> column of the array are sorted and increase monotonically (if that matters).
>>
>> I am new to IDL, so will greatly appreciate any suggestions.
>
> If you can guarantee that there won't be any "misses", ie all
> possibilities are in your second table, then VALUE_LOCATE is your
> friend. This is new in IDL 5.3, but presumably you have at least this
> version. If not, then see my web page for a drop-in substitute. :-)
>
> You are basically done then!
>
> wh = value_locate(col1, vector)
> y = col2(wh)
>
> Cogitate on that for awhile and I think you will be satisfied.
> Good luck,
> Craig
>
> Web page: http://cow.physics.wisc.edu/~craigm/idl/idl.html (Main listing)
>
> --
> ------------------------------------------------------------ --------------
> Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
> Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
> ------------------------------------------------------------ --------------
|
|
|
Re: Finding values in an array [message #25574 is a reply to message #25476] |
Sun, 24 June 2001 23:18  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Bob Fugate <rqfugate@mindspring.com> writes:
> I have a vector containing a very, very large number of long integer values.
>
> I want to compare the value of each element in the vector to the values of
> the elements in the first column of a two column array until there is a
> match, and then extract the corresponding number in the second column (e.g.
> by using WHERE) of the array.
>
> Does anyone know a way to do this without using a loop? I realise that
> organizing the searched array as two rows may speed this up, however, I am
> trying to avoid using a loop. The numbers in the vector vary randomly (and
> it is important to preserve the original order) but the numbers in the first
> column of the array are sorted and increase monotonically (if that matters).
>
> I am new to IDL, so will greatly appreciate any suggestions.
If you can guarantee that there won't be any "misses", ie all
possibilities are in your second table, then VALUE_LOCATE is your
friend. This is new in IDL 5.3, but presumably you have at least this
version. If not, then see my web page for a drop-in substitute. :-)
You are basically done then!
wh = value_locate(col1, vector)
y = col2(wh)
Cogitate on that for awhile and I think you will be satisfied.
Good luck,
Craig
Web page: http://cow.physics.wisc.edu/~craigm/idl/idl.html (Main listing)
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|