spey.helper_functions.covariance_to_correlation#
- spey.helper_functions.covariance_to_correlation(covariance_matrix: ndarray) ndarray[source]#
Convert covariance matrix into correlation matrix.
Computes \(\rho_{ij} = \Sigma_{ij} / (\sigma_i \sigma_j)\) where \(\sigma_i = \sqrt{\Sigma_{ii}}\) are the per-bin standard deviations.
- Parameters:
covariance_matrix (
np.ndarray) – A real NxN covariance matrix \(\Sigma\) with strictly positive diagonal entries.- Returns:
Correlation matrix \(\rho\) of shape
(N, N).- Return type:
np.ndarray
Example
>>> import numpy as np >>> from spey.helper_functions import covariance_to_correlation >>> cov = np.array([[4.0, 2.4], [2.4, 16.0]]) >>> covariance_to_correlation(cov) array([[1. , 0.3], [0.3, 1. ]])