[R] A slightly unorthodox matrix product.
Rolf Turner
r@turner @ending from @uckl@nd@@c@nz
Sat Aug 4 07:52:37 CEST 2018
Can anyone think of a sexy way of forming following "product"?
Given matrices A and B, both with m rows, form a 3 dimensional array C
such that:
C[i,j,k] = A[i,j]*B[i,k]
I *think* that the following does what I want. (I keep confusing
myself, so I'm not sure!)
library(abind)
xxx <- lapply(1:nrow(a),function(i,a,b){a[i,]%o%b[i,]},a=A,b=B)
do.call(abind,c(xxx,list(along=3)))
Is there a cleverer way?
cheers,
Rolf Turner
--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
More information about the R-help
mailing list