|
Re: idl array operations [message #47764 is a reply to message #47757] |
Tue, 28 February 2006 22:50  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
mmeron@cars3.uchicago.edu writes:
> In article <1141168957.087822.106350@i39g2000cwa.googlegroups.com>, "alex922@gmail.com" <alex922@gmail.com> writes:
>> Hi,
>>
>> I'm pretty new to IDL and someone told me to avoid loops.
>>
>> I have the following problem. I have an array of elements whose values
>> range from 0 to 360, and I have to subtract a number if the value is
>> greater than 180.
...
> Taking your array as arr and the nuber to be subtracted as x, the line
> would be
> arr = arr - x*(arr gt 180)
Or, if you are trying to map longitude in the 0 to 360 range to the
-180 to 180 range, I often would use this:
LONGITUDE = ((LONGITUDE + 180) MOD 360) - 180
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: idl array operations [message #47766 is a reply to message #47764] |
Tue, 28 February 2006 15:34  |
mmeron
Messages: 44 Registered: October 2003
|
Member |
|
|
In article <1141168957.087822.106350@i39g2000cwa.googlegroups.com>, "alex922@gmail.com" <alex922@gmail.com> writes:
> Hi,
>
> I'm pretty new to IDL and someone told me to avoid loops.
>
> I have the following problem. I have an array of elements whose values
> range from 0 to 360, and I have to subtract a number if the value is
> greater than 180.
>
> My initial reaction is to create a loop and use condition statements to
> perform the calculations.
>
> Is there a 'one liner' array operation which would allow me to do this
> without using loops?
>
> Thanks,
> Alex
>
Taking your array as arr and the nuber to be subtracted as x, the line
would be
arr = arr - x*(arr gt 180)
Mati Meron | "When you argue with a fool,
meron@cars.uchicago.edu | chances are he is doing just the same"
|
|
|
|
Re: idl array operations [message #47768 is a reply to message #47767] |
Tue, 28 February 2006 15:26  |
Paul Van Delst[1]
Messages: 1157 Registered: April 2002
|
Senior Member |
|
|
alex922@gmail.com wrote:
> Hi,
>
> I'm pretty new to IDL and someone told me to avoid loops.
>
> I have the following problem. I have an array of elements whose values
> range from 0 to 360, and I have to subtract a number if the value is
> greater than 180.
>
> My initial reaction is to create a loop and use condition statements to
> perform the calculations.
>
> Is there a 'one liner' array operation which would allow me to do this
> without using loops?
Dunno about a one-liner:
loc=where(data gt 180.0,count)
if (count gt 0) then data[loc]=data[loc]-number
There's probably a solution via HISTOGRAM, too. :o)
paulv
--
Paul van Delst
CIMSS @ NOAA/NCEP/EMC
|
|
|