Getting rid of loops [message #18932] |
Thu, 17 February 2000 00:00  |
Jacob Noel-Storr
Messages: 1 Registered: February 2000
|
Junior Member |
|
|
I am trying to create non-loopy IDL code for a project I am working on.
I have a very long list of integers ('cycle numbers') and I need some way of
creating an array that consists of just the cycle numbers. For example if I
had:
> cycles=[2,2,2,2,2,6,6,7,7,7,9,9,9,27,27,27]
then I would want a function which would do this kid of thing:
> print,fn(cycles)
[2,6,7,9,27]
At the moment this is done by looping through the data twice. Once to count
how many different values there are and once to write the different values
into an array.
Any suggestions about how this could be achieved without the two 'for'
loops?
Thanks,
Jacob
--
Jacob Noel-Storr
Astronomy Department
Columbia University / Biosphere 2 Center
www.astro.bio2.edu/jacob/
jake@astro.columbia.edu
|
|
|
Re: Getting rid of loops [message #19216 is a reply to message #18932] |
Fri, 03 March 2000 00:00  |
Nando Iavarone
Messages: 48 Registered: December 1998
|
Member |
|
|
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Jacob Noel-Storr wrote:
<blockquote TYPE=CITE>I am trying to create non-loopy IDL code for a project
I am working on.
<p>I have a very long list of integers ('cycle numbers') and I need some
way of
<br>creating an array that consists of just the cycle numbers. For example
if I
<br>had:
<p>> cycles=[2,2,2,2,2,6,6,7,7,7,9,9,9,27,27,27]
<p>then I would want a function which would do this kid of thing:
<p>> print,fn(cycles)
<br>[2,6,7,9,27]</blockquote>
if your repeated values are adjacent, you can use
<br>the "uniq" function.
<br>
<pre>--
Nando Iavarone
Advanced Computer System - SPACE DIVISION
via Lazzaro Belli, 23
00040 Frascati - RM
Tel: +39-6-944091 (switchboard)
9440968 (direct)
E-mail:
f.iavarone@acsys.it
FrdndVrn@altavista.net</pre>
</html>
|
|
|