def ks_2samp(data1, data2):
 (data1, data2) = lmap(np.asarray, (data1, data2))
 n1 = data1.shape[0]
 n2 = data2.shape[0]
 n1 = len(data1)
 n2 = len(data2)
 data1 = np.sort(data1)
 data2 = np.sort(data2)
 data_all = np.concatenate([data1, data2])
 cdf1 = (np.searchsorted(data1, data_all, side='right') / (1.0 * n1))
 cdf2 = (np.searchsorted(data2, data_all, side='right') / (1.0 * n2))
 d = np.max(np.absolute((cdf1 - cdf2)))
 en = np.sqrt(((n1 * n2) / float((n1 + n2))))
 try:
  prob = ksprob((((en + 0.12) + (0.11 / en)) * d))
 except:
  prob = 1.0
 return (d, prob)

def ks_2samp ( data1 , data2 ) : ( data1 , data2 ) = lmap ( np . asarray , ( data1 , data2 ) ) n1 = data1 . shape [ 0 ] n2 = data2 . shape [ 0 ] n1 = len ( data1 ) n2 = len ( data2 ) data1 = np . sort ( data1 ) data2 = np . sort ( data2 ) data_all = np . concatenate ( [ data1 , data2 ] ) cdf1 = ( np . searchsorted ( data1 , data_all , side = 'right' ) / ( 1.0 * n1 ) ) cdf2 = ( np . searchsorted ( data2 , data_all , side = 'right' ) / ( 1.0 * n2 ) ) d = np . max ( np . absolute ( ( cdf1 - cdf2 ) ) ) en = np . sqrt ( ( ( n1 * n2 ) / float ( ( n1 + n2 ) ) ) ) try : prob = ksprob ( ( ( ( en + 0.12 ) + ( 0.11 / en ) ) * d ) ) except : prob = 1.0 return ( d , prob )
computes the kolmogorov-smirnov statistic on 2 samples .