diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2012-11-13 01:44:33 +0100 |
---|---|---|
committer | Ondřej Čertík <ondrej.certik@gmail.com> | 2012-12-06 14:22:57 -0800 |
commit | 7b10fc90097c514e24cd477af5c1e47349d1c0ac (patch) | |
tree | d207e5a3cc093dfa1390e68d14ff56930c1b2b53 /numpy/random | |
parent | 2da0d2288667202ff489ba7b922b534ca98768f3 (diff) | |
download | numpy-7b10fc90097c514e24cd477af5c1e47349d1c0ac.tar.gz |
BUG: Do not sort new indices in random.choice.
Random choice used np.unique to find new indices when replace
was False and p given. This is wrong since unique will sort the
indices. This solves the bug, but likely not ideal.
Diffstat (limited to 'numpy/random')
-rw-r--r-- | numpy/random/mtrand/mtrand.pyx | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx index 5f0e38660..a39e67fac 100644 --- a/numpy/random/mtrand/mtrand.pyx +++ b/numpy/random/mtrand/mtrand.pyx @@ -1049,8 +1049,9 @@ cdef class RandomState: cdf = np.cumsum(p) cdf /= cdf[-1] new = cdf.searchsorted(x, side='right') - new = np.unique(new) - flat_found[n_uniq:n_uniq + new.size] = new + _, unique_indices = np.unique(new, return_index=True) + unique_indices.sort() + flat_found[n_uniq:n_uniq + new.size] = new[unique_indices] n_uniq += new.size idx = found else: |