def low_rank_repr(X, n_dim): U, S, V = svd(X.T,full_matrices=False) mask = S > 1 V = V[mask] S = S[mask] R = (V.T * (1 - S**-2)).dot(V) return R