def canorth(S):
    "Canonical orthogonalization U/sqrt(lambda)"
    E,U = np.linalg.eigh(S)
    for i in range(len(E)):
        U[:,i] = U[:,i] / np.sqrt(E[i])
    return U
def canorth ( S ) : E , U = np . linalg . eigh ( S ) for i in range ( len ( E ) ) : U [ : , i ] = U [ : , i ] / np . sqrt ( E [ i ] ) return U
Canonical orthogonalization U/sqrt(lambda)