From d63efe9965ce72a8954185a1d67a16c91555b30d Mon Sep 17 00:00:00 2001 From: Raphael Vallat Date: Tue, 3 Sep 2024 15:58:27 +0200 Subject: [PATCH] Improve speed of multivariate_normality --- src/pingouin/multivariate.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pingouin/multivariate.py b/src/pingouin/multivariate.py index 5dad7bf9..e306187a 100644 --- a/src/pingouin/multivariate.py +++ b/src/pingouin/multivariate.py @@ -78,7 +78,8 @@ def multivariate_normality(X, alpha=0.05): # Squared-Mahalanobis distances Dj = np.diag(np.linalg.multi_dot([difT, S_inv, difT.T])) Y = np.linalg.multi_dot([X, S_inv, X.T]) - Djk = -2 * Y.T + np.repeat(np.diag(Y.T), n).reshape(n, -1) + np.tile(np.diag(Y.T), (n, 1)) + Y_diag = np.diag(Y) + Djk = -2 * Y.T + Y_diag + Y_diag[..., None] # Smoothing parameter b = 1 / (np.sqrt(2)) * ((2 * p + 1) / 4) ** (1 / (p + 4)) * (n ** (1 / (p + 4)))