comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Re: Vector Calculation Q

Re: Vector Calculation Q
type: item
description: handy@gemini.oscs.montana.edu (Brian Handy) wrote: > Hi, > I've got a puzzler I'd like to figure out. I want to do > sort of a "running integral on a vector, e.g. if I'm given > a = [1, 4, 2, 6, 3, 4, 2, 6] > Then I can easily do > for i=0, (size(a))(1)-1 > b(i) = total(a(0:i))) > to get... > b = [1, 5, 7, 13, 16, 20, 22, 28] > ...I'd like to do this with a vector instead of the loop. > Any ideas? My suggestion is not sensible if you have to compute the thing just one time. If, on the other hand, you perform the computation several times, the following may prove useful: ;;;;;;;; pro init ;;;;;;;; common globalKernel, m, n n = 8 m = intarr( n, n ) for i=0,n-1 do begin for j=i, n-1 do begin m(i,j) = 1 endfor endfor end ;;;;;;;;;;; pro compute ;;;;;;;;;;; common globalKernel, m, n a = [1, 4, 2, 6, 3, 4, 2, 6] print, a # m end ;;;;;;;; pro test ;;;;;;;; init compute end ;;;;;;;;;;;;; Well, it reduces to building an upper triangular matrix of all ones in the upper half; maybe there is some better way of initializing it than mine! I suspect, however, that you are not satisfied with my answer :( Cheers Andrea Andrea Spinelli - Ismes Spa. 9, Via Pastrengo, 24068 Seriate BG, Italy tel.: +39-35-307777 fax.: +39-35-302999 e-mail: aspinelli@ismes.it "Truth hurts, but pimples much more"
creator: aspinelli
date: 1997-01-14T08:00:00-00:00