diff options
author | Matti Picus <matti.picus@gmail.com> | 2018-10-12 11:27:32 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-12 11:27:32 +0300 |
commit | c8007603bf44a93726191d0241db8c50e9c31de8 (patch) | |
tree | b8735741084dc59d812468c5041d40f2f9271db4 /numpy | |
parent | bba4a7db7a22acdf132ad40f0d840e698c87bfcd (diff) | |
parent | efd47971b8d778263cb12ffe42fb89edcb75b765 (diff) | |
download | numpy-c8007603bf44a93726191d0241db8c50e9c31de8.tar.gz |
Merge pull request #11771 from asnasnasn/shuf-mm
BUG: Make `random.shuffle` work on 1-D instances of `ndarray` subclasses
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/random/mtrand/mtrand.pyx | 5 | ||||
-rw-r--r-- | numpy/random/tests/test_random.py | 4 |
2 files changed, 6 insertions, 3 deletions
diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx index ab5f64336..80585bda4 100644 --- a/numpy/random/mtrand/mtrand.pyx +++ b/numpy/random/mtrand/mtrand.pyx @@ -4836,9 +4836,8 @@ cdef class RandomState: self._shuffle_raw(n, sizeof(npy_intp), stride, x_ptr, buf_ptr) else: self._shuffle_raw(n, itemsize, stride, x_ptr, buf_ptr) - elif isinstance(x, np.ndarray) and x.ndim > 1 and x.size: - # Multidimensional ndarrays require a bounce buffer. - buf = np.empty_like(x[0]) + elif isinstance(x, np.ndarray) and x.ndim and x.size: + buf = np.empty_like(x[0,...]) with self.lock: for i in reversed(range(1, n)): j = rk_interval(i, self.internal_state) diff --git a/numpy/random/tests/test_random.py b/numpy/random/tests/test_random.py index 42816a943..276517363 100644 --- a/numpy/random/tests/test_random.py +++ b/numpy/random/tests/test_random.py @@ -466,6 +466,10 @@ class TestRandomDist(object): lambda x: [(i, i) for i in x], lambda x: np.asarray([[i, i] for i in x]), lambda x: np.vstack([x, x]).T, + # gh-11442 + lambda x: (np.asarray([(i, i) for i in x], + [("a", int), ("b", int)]) + .view(np.recarray)), # gh-4270 lambda x: np.asarray([(i, i) for i in x], [("a", object, 1), |