// make sure that only the real part of the value
// is used, if `complex` is returned
values = sp.real(values)
// calculate loadings
// if values are smaller than 0, set them to zero
loadings = sp.dot(vectors, sp.diag(sp.sqrt(np.maximum(values, 0))))
After Change
// sort the values and vectors in ascending order
values = values[::-1][:n_factors]
vectors = vectors[:, ::-1][:, :n_factors]
// calculate loadings
// if values are smaller than 0, set them to zero