Skip to content

Instantly share code, notes, and snippets.

@dirmeier
Last active May 19, 2020 22:48

Revisions

  1. dirmeier renamed this gist May 19, 2020. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions khatri_rao.python → khatri_rao.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    def khatri_rao(J, X):
    # as needed to compute random effects model matrices
    # reference: http://dx.doi.org/10.18637/jss.v067.i01
    #
    # 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:])
  2. dirmeier created this gist May 19, 2020.
    6 changes: 6 additions & 0 deletions khatri_rao.python
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    def khatri_rao(J, X):
    # as needed to compute random effects model matrices
    # reference: http://dx.doi.org/10.18637/jss.v067.i01
    #
    Z = J[..., :, np.newaxis, :] * X[..., np.newaxis, :, :]
    return Z.reshape((-1,) + Z.shape[2:])