<s> import numpy as np <EOL> from numpy import asarray <EOL> from scipy . stats import ksprob <EOL> def ks_2samp ( data1 , data2 , signed = False ) : <EOL> """<STR_LIT>""" <EOL> data1 , data2 = map ( asarray , ( data1 , data2 ) ) <EOL> n1 = data1 . shape [ <NUM_LIT:0> ] <EOL> n2 = data2 . shape [ <NUM_LIT:0> ] <EOL> n1 = len ( data1 ) <EOL> n2 = len ( data2 ) <EOL> data1 = np . sort ( data1 ) <EOL> data2 = np . sort ( data2 ) <EOL> data_all = np . concatenate ( [ data1 , data2 ] ) <EOL> cdf1 = np . searchsorted ( data1 , data_all , side = '<STR_LIT:right>' ) / ( <NUM_LIT:1.0> * n1 ) <EOL> cdf2 = ( np . searchsorted ( data2 , data_all , side = '<STR_LIT:right>' ) ) / ( <NUM_LIT:1.0> * n2 ) <EOL> diff = cdf1 - cdf2 <EOL> ind = np . argmax ( np . absolute ( diff ) ) <EOL> d = diff [ ind ] <EOL> absd = np . absolute ( d ) <EOL> en = np . sqrt ( n1 * n2 / float ( n1 + n2 ) ) <EOL> try : <EOL> prob = ksprob ( ( en + <NUM_LIT> + <NUM_LIT> / en ) * absd ) <EOL> except : <EOL> prob = <NUM_LIT:1.0> <EOL> if signed : <EOL> return d , prob <EOL> else : <EOL> return absd , prob </s>
