Last active
May 19, 2020 22:48
-
-
Save dirmeier/73b23fa21c8dfbcf9d041b15f980d96f to your computer and use it in GitHub Desktop.
Khatri-Rao product for any kind of matrices.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def khatri_rao(J, X): | |
# as needed to compute random effects model matrices | |
# references: | |
# - http://dx.doi.org/10.18637/jss.v067.i01 | |
# - https://stat.ethz.ch/R-manual/R-patched/library/Matrix/html/KhatriRao.html | |
Z = J[..., :, np.newaxis, :] * X[..., np.newaxis, :, :] | |
return Z.reshape((-1,) + Z.shape[2:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment