def clip_spectrum(s, k, discard=0.001):
 rel_spectrum = np.abs((1.0 - np.cumsum((s / np.sum(s)))))
 small = (1 + len(np.where((rel_spectrum > min(discard, (1.0 / k))))[0]))
 k = min(k, small)
 logger.info('keeping %i factors (discarding %.3f%% of energy spectrum)', k, (100 * rel_spectrum[(k - 1)]))
 return k

def clip_spectrum ( s , k , discard = 0.001 ) : rel_spectrum = np . abs ( ( 1.0 - np . cumsum ( ( s / np . sum ( s ) ) ) ) ) small = ( 1 + len ( np . where ( ( rel_spectrum > min ( discard , ( 1.0 / k ) ) ) ) [ 0 ] ) ) k = min ( k , small ) logger . info ( 'keeping %i factors (discarding %.3f%% of energy spectrum)' , k , ( 100 * rel_spectrum [ ( k - 1 ) ] ) ) return k
given eigenvalues s .