1

Is what I've represented in the R code below an example of a more general matrix product?

I know this isn't a Kronecker or Hadamard product. But this is such a common operation in my world that I'm starting think this must be an example of some more general matrix product.

ff <- matrix(1:6,ncol=2)
# [,1] [,2]
# [1,]    1    4
# [2,]    2    5
# [3,]    3    6

bb <- matrix(7:10,ncol=2)
# [,1] [,2]
# [1,]    7    9
# [2,]    8   10

# DESIRE:
#  7 36
# 14 45
# 21 54
#  8 40
# 16 50
# 24 60

# This works
rr1 <- t(t(ff) * bb[1,])
rr2 <- t(t(ff) * bb[2,])
rbind(rr1,rr2)
# [,1] [,2]
# [1,]    7   36
# [2,]   14   45
# [3,]   21   54
# [4,]    8   40
# [5,]   16   50
# [6,]   24   60

# This works too
ffa <- matrix(rep(t(ff),2), ncol=2, byrow=T)
bba <- matrix(rep(bb,each=3), ncol=2)
ffa * bba
# [,1] [,2]
# [1,]    7   36
# [2,]   14   45
# [3,]   21   54
# [4,]    8   40
# [5,]   16   50
# [6,]   24   60
lowndrul
  • 259

1 Answers1

1

This turns out to be a Khatri-Rao matrix product. From wikipedia:

A column-wise Kronecker product of two matrices may also be called the Khatri–Rao product.

Discussion can be found in this solution over on StackOverflow.

lowndrul
  • 259