skfolio.utils.stats.symmetrize#
- skfolio.utils.stats.symmetrize(matrix, where=None)[source]#
In-place symmetrization: \(M \leftarrow (M + M^T) / 2\).
When
whereis provided, only the sub-block indexed by the mask is symmetrized, leaving the rest of the matrix untouched. This is useful for matrices that contain NaN rows/columns where a full transpose would propagate NaNs into the finite block.- Parameters:
- matrixndarray of shape (n, n)
Square matrix to symmetrize in-place.
- wherendarray of shape (n,) or None, default=None
Boolean mask indicating which rows/columns to include. If
None, the full matrix is symmetrized.