def _ks_Z(a, b): result = stats.ks_2samp(a, b) n = len(a) m = len(b) return result.statistic / np.sqrt((n + m) / (n * m))