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

Home » Public Forums » archive » how to calculate a running total of a vector
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
how to calculate a running total of a vector [message #3218] Fri, 02 December 1994 09:51 Go to next message
VUKOVIC is currently offline  VUKOVIC
Messages: 6
Registered: December 1994
Junior Member
Suppose I have a vector v.
I want to generate a vector vv whose i-th element is a sum of the first i
elements of v. How to do it fast -- without loops?

I thought of multiplying a matrix with 1's on and bellow its diagonal by v.
That would do it, but seems like a bit of overkill.
Re: how to calculate a running total of a vector [message #3223 is a reply to message #3218] Fri, 02 December 1994 13:34 Go to previous message
chase is currently offline  chase
Messages: 62
Registered: May 1993
Member
In article <3bnmri$e91@news.doit.wisc.edu> VUKOVIC@uwmfe.neep.wisc.edu (Mirko Vukovic) writes:

Mirko> Suppose I have a vector v. I want to generate a vector vv
Mirko> whose i-th element is a sum of the first i elements of v. How
Mirko> to do it fast -- without loops?

Mirko> I thought of multiplying a matrix with 1's on and bellow its
Mirko> diagonal by v. That would do it, but seems like a bit of
Mirko> overkill.

This will work, but it is overkill also. I probably does the same
amount of computations as your matrix multiply solution.

running_sum = (convol([0,v],replicate(1.,n_elements(v)),center=0,/edge_tru n))(1:*)


Chris Chase
--
===============================
Bldg 24-E188
The Applied Physics Laboratory
The Johns Hopkins University
Laurel, MD 20723-6099
(301)953-6000 x8529
chris.chase@jhuapl.edu
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Princip Components, Factor Analysis software available?
Next Topic: Please explain this if you can: (short)

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

Current Time: Fri Oct 10 01:31:29 PDT 2025

Total time taken to generate the page: 1.44026 seconds