Re: Summing arrays without loops [message #27313] |
Tue, 16 October 2001 13:24 |
Mark Hadfield
Messages: 783 Registered: May 1995
|
Senior Member |
|
|
From: "Matt Jolly" <mattj@ntsg.umt.edu>
> I have a 3d array of daily precipitation data for the globe that I would
> like to sum for the entire year but I would like to do it without looping.
> The array is initialized as follows:
>
> IDL> data = fltarr(365,192,94)
>
> where 365 is the number of days, 192 is the number of longitudes and 94 is
> the number of latitudes.
>
> Is there a way to sum the daily values without writing a nested loop?
There sure is: TOTAL(data, 1)
---
Mark Hadfield
m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield
National Institute for Water and Atmospheric Research
--
Posted from clam.niwa.cri.nz [202.36.29.1]
via Mailgate.ORG Server - http://www.Mailgate.ORG
|
|
|
Re: Summing arrays without loops [message #27316 is a reply to message #27313] |
Tue, 16 October 2001 13:07  |
Ken Mankoff
Messages: 158 Registered: February 2000
|
Senior Member |
|
|
On Tue, 16 Oct 2001, Matt Jolly wrote:
> Hello IDL users,
>
> I have a 3d array of daily precipitation data for the globe that I would
> like to sum for the entire year but I would like to do it without looping.
> The array is initialized as follows:
>
> IDL> data = fltarr(365,192,94)
>
> where 365 is the number of days, 192 is the number of longitudes and 94 is
> the number of latitudes.
>
> Is there a way to sum the daily values without writing a nested loop?
>
help, total( data, 1 )
<Expression> FLOAT = Array[192, 94]
or, with a mask of values gt 0:
mask = total( data gt 0, 1 )
sum = total( data, 1 )
result = sum / (mask>1)
-k.
--
Ken Mankoff
LASP://303.492.3264
http://lasp.colorado.edu/~mankoff/
|
|
|