def corr_clipped(corr, threshold=1e-15):
 (x_new, clipped) = clip_evals(corr, value=threshold)
 if (not clipped):
  return corr
 x_std = np.sqrt(np.diag(x_new))
 x_new = ((x_new / x_std) / x_std[:, None])
 return x_new

def corr_clipped ( corr , threshold = 1e-15 ) : ( x_new , clipped ) = clip_evals ( corr , value = threshold ) if ( not clipped ) : return corr x_std = np . sqrt ( np . diag ( x_new ) ) x_new = ( ( x_new / x_std ) / x_std [ : , None ] ) return x_new
find a near correlation matrix that is positive semi-definite this function clips the eigenvalues .