Re: cumulative sum

From: Verica Savic-Jovcic <verica_at_nyahnyahspammersnyahnyah>
Date: Thu, 15 Feb 2007 11:07:12 -0800

Hi All,

In the sum and dim_sum, you can always define the indices over which
you want to do sum. So, instead of the do loop done here, one can
just do sum(tm(:nmonth-1)).
However, if you want to have an array of cumulative sums, I'm afraid
I don't know a way to avoid a do loop.

Verica

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.atmos.ucla.edu/~verica/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"The art of being wise is the art of knowing what to overlook."
                                                 William James

On Feb 15, 2007, at 8:09 AM, Keith Lindsay wrote:

> On Thu, 15 Feb 2007, Dennis Shea wrote:
>
>>> Is there any function to calculate cumulative sum of variable. I
>>> would like
>>> to avoid the following loop.
>>>
>>> ; loop to compute cumulative sum of number of days
>>> tm=new(dimsizes(month),"integer")
>>> a=0
>>> do i=0,nmonth-1
>>> tm(i)=month(i)+a
>>> a=tm(i)
>>> end do
>>> ------------------------------
>>
>> sum, dim_sum
>>
>> http://www.ncl.ucar.edu/Document/Functions/Built-in/sum.shtml
>> http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_sum.shtml
>>
>> ----
>> If you are looking for a function that does "something" [eg, sum]
>> type sum in the Search box in the upper left of all NCL web pages.
>>
>
> Dennis,
>
> I don't think sum and dim_sum do what the original poster is asking
> for.
> He is looking for a cumulative sum, which is sometimes called an
> indefinite or running sum. At times I have wanted the same
> functionality. In matlab you can use cumsum and in ferret you can use
> the @rsu transformation. I have not come across a way to do it in NCL
> without resorting to a loop. If someone knows how to do this and avoid
> the loop, I'd love to hear about it as well.
>
> Keith
>
> --
> ******************************************************************
> Keith Lindsay http://www.cgd.ucar.edu/oce/klindsay/
> email: klindsay_at_ucar.edu phone: 303-497-1722 fax: 303-497-1700
> _______________________________________________
> ncl-talk mailing list
> ncl-talk_at_ucar.edu
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Feb 15 2007 - 12:07:12 MST

This archive was generated by hypermail 2.2.0 : Thu Feb 22 2007 - 14:54:01 MST