Message-ID: <5F47C0A6-D24A-4AD9-BC13-25F99FE47A8F@uva.nl>
Date: 2008-03-26T21:58:16Z
From: Ingmar Visser
Subject: avoiding loops
Hi,
I need to compute an array from a matrix and an array:
A <- array(1:20,c(2,2,5))
B <- matrix(1:10,5)
And I would like the result to be an array consisting of the following:
rbind(A[1,,1]*B[1,],
A[2,,1]*B[1,])
rbind(A[1,,2]*B[2,],
A[2,,2]*B[2,])
rbind(A[1,,3]*B[2,],
A[2,,3]*B[2,])
etc.
Hence the result should have the same dimension as A, ie a series of
2 by 2 matrices.
Short of a for loop over the the last index of A I have struggled
with versions of apply but
to no avail ...
Any insights much appreciated,
Best, Ingmar