Folks:
1. Well, should have known better... I was wrong about what I said in
my earlier post below.
2. Here's yet another way to skin the cat using matrix multiplication
that is, maybe, a bit faster than using reduce.
First, the three methods (left as a homework exercise to see how/why they work
You haven't told us the dimension of the array, which is useful to
when deciding on approach, especially 'm'. /H
On Mon, Mar 28, 2011 at 5:56 PM, Giuseppe wrote:
> Dennis,
>
> Yes, Reduce works, but unfortunately it does not speed up the
> evaluation time (actually, it makes it a little bit slow
Arrays are vectors stored in column major order. Hence
H <- apply( H12*rep(hessian_lambda,e = n*k), 1:2, sum)
## but check that this gives what you want
I'm pretty sure this is faster than the alternatives that were
proposed, but whether it's much (or even noticeably) faster, I don't
know.
--
Giuseppe gmail.com> writes:
>
> Dennis,
>
> Yes, Reduce works, but unfortunately it does not speed up the
> evaluation time (actually, it makes it a little bit slower).
>
> Thank you anyway.
I have an alternate solution that I would have expected to
be faster but is actually much slower for
Dennis,
Yes, Reduce works, but unfortunately it does not speed up the
evaluation time (actually, it makes it a little bit slower).
Thank you anyway.
On Tue, Mar 29, 2011 at 2:21 AM, Dennis Murphy wrote:
> Hi:
>
> Is this what you're after?
>
> m <- array(1:27, c(3, 3, 3))
> xx <- 1:3
> Reduce
Hi:
Is this what you're after?
m <- array(1:27, c(3, 3, 3))
xx <- 1:3
Reduce('+', lapply(xx, function(k) xx[k] * m[, , k]))
> m
, , 1
[,1] [,2] [,3]
[1,]147
[2,]258
[3,]369
, , 2
[,1] [,2] [,3]
[1,] 10 13 16
[2,] 11 14 17
[3,] 12 1
I have the following situation.
H12 is an array of dimension (n,k,m) and hessian_lambda is a numeric
of length m.
I need to multiply each matrix H12[,,1], H12[,,2], ..., H12[,m] by
hessian_lambda[1], hessian_lambda[2], ..., hessian_lambda[m],
respectively, and then add the resulting (n,k) matrice
7 matches
Mail list logo