Skip to content
Prev 273577 / 398506 Next

speed up this algorithm (apply-fuction / 4D array)

here's another one - which is easier to generalize:

x <- array(rnorm(50 * 50 * 50 * 91, 0, 2), dim=c(50, 50, 50, 91))
y <- x [,,,1:90] # decide yourself what to do with slice 91, but
                  # 91 is not divisible by 3
system.time ({
dim (y) <- c (50, 50, 50, 3, 90 %/% 3)
y <- aperm (y, c (4, 1:3, 5))
v2 <- colMeans (y)
})
        User      System verstrichen
        0.32        0.08        0.40

(my computer is a bit slower than Bill's:)
 > system.time (v1 <- f1 (x))
        User      System verstrichen
       0.360       0.030       0.396

Claudia


Am 05.10.2011 20:24, schrieb William Dunlap: