Skip to content

Instantly share code, notes, and snippets.

@ytakashina
Last active April 8, 2018 02:36
Show Gist options
  • Save ytakashina/2767dda34167f4bec3ebff65c857d18f to your computer and use it in GitHub Desktop.
Save ytakashina/2767dda34167f4bec3ebff65c857d18f to your computer and use it in GitHub Desktop.
  • 全組み合わせ列挙
np.hstack([np.repeat(X, len(Y), axis=0), np.tile(Y, [len(X), 1])])
  • マハラノビス距離計算
def mahalanobis_distance(X, mean=None, cov=None):
    mean = np.mean(X, axis=0) if mean is None else mean
    cov = np.cov(X, rowvar=0) if cov is None else cov
    pre = np.linalg.inv(cov)
    X_ = X - mean.reshape(1, -1)
    return np.sqrt(np.sum(X_.dot(pre) * X_, axis=1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment