[R] Multiply each depth level of an array with another vector element

Wu Gong wg2f at mtmail.mtsu.edu
Fri Aug 6 05:34:37 CEST 2010


I have only achieved a half improvement.

x <- array(1:24000000*1, dim = c(200,300,400))
y <- 1:400*1
ptm <- proc.time()
z <- x*as.vector(t(replicate(dim(x)[1]*dim(x)[2], y[1:dim(x)[3]]))) 
"replicate:"
proc.time() - ptm

x <- array(1:24000000*1, dim = c(200,300,400))
y <- 1:400*1
ptm <- proc.time()
z <- x*rep(y[1:dim(x)[3]],each=dim(x)[1]*dim(x)[2])
"rep:"
proc.time() - ptm

-----
A R learner.
-- 
View this message in context: http://r.789695.n4.nabble.com/Multiply-each-depth-level-of-an-array-with-another-vector-element-tp2315537p2315860.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list