comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Summing arrays without loops
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Summing arrays without loops [message #27313] Tue, 16 October 2001 13:24
Mark Hadfield is currently offline  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 Go to previous message
Ken Mankoff is currently offline  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/
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDL Help Gone Missing
Next Topic: Summing arrays without loops

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 17:09:05 PDT 2025

Total time taken to generate the page: 0.00483 seconds