Hi Rolf, A few edits because (i) nrow(a) should be nrow(A) and (ii) you have calculated C[j,k,i] = A[i,j]*B[i,k], (iii) minor style change on lapply.
library(abind) xxx <- lapply(1:nrow(A),function(i){A[i,]%o%B[i,]}) yyy <- do.call(abind,c(xxx,list(along=3))) zzz <- aperm(yyy,c(3,1,2)) HTH, Eric On Sat, Aug 4, 2018 at 8:52 AM, Rolf Turner <r.tur...@auckland.ac.nz> wrote: > > 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 > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posti > ng-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.