[R] Re: General Matrix Inner Product?

ggrothendieck@yifan.net ggrothendieck at yifan.net
Sat Mar 8 02:50:52 CET 2003


This is inefficient and its is not precisely the set of arguments you requested but its 
concise and perhaps its close enough.

> inner = function(a,b,f,g) apply(apply(outer(a,b,FUN=g),c(1,4),diag),2:3,f)
> a=matrix(1:8,2,4)
> b=t(a)
> inner(a,b,sum,"*")
     [,1] [,2]
[1,]   84  100
[2,]  100  120
> a%*%b
     [,1] [,2]
[1,]   84  100
[2,]  100  120
> inner(a,b,all,"==")
      [,1]  [,2]
[1,]  TRUE FALSE
[2,] FALSE  TRUE



More information about the R-help mailing list