Cumulative product of matrix? -
i need write code calculate cumulative product of matrix. example, if
= ( 1 2 3 | 4 3 2 ) cum.sum(a) = ( 1 2 6 | 4 24 144 )
is there algorithm doing this?
i'll use r, c, matlab or octave.
a <- matrix(c(1,2,3,4,3,2),byrow=true,nrow=2) i'm guessing want cumulative product of (k,l) less than (i,j) ... ?
b <- nr <- nrow(b) nc <- ncol(b) (i in 1:max(nr,nc)) { if (i<=nr) b[i,i:nc] <- cumprod(b[i,])[i:nc] } this works example: might have little careful generalizing case more rows columns ...
Comments
Post a Comment