R/krprod.R

krprod <- 
  function(X,Y){
    # Khatri-Rao product (columnwise Kronecker product)
    # Nathaniel E. Helwig ([email protected])
    # last updated: April 9, 2015
    
    xdim <- dim(X)
    ydim <- dim(Y)
    if(xdim[2]!=ydim[2]){stop("X and Y must have same number of columns.")}
    XkrY <- matrix(0,ydim[1]*xdim[1],xdim[2])
    for(u in 1:xdim[2]){
      XkrY[,u] <- kronecker(X[,u],Y[,u])
    }
    XkrY
  }

Try the multiway package in your browser

Any scripts or data that you put into this service are public.

multiway documentation built on May 2, 2019, 6:47 a.m.