diff options
author | Warren Weckesser <warren.weckesser@gmail.com> | 2019-10-08 11:05:26 -0400 |
---|---|---|
committer | Warren Weckesser <warren.weckesser@gmail.com> | 2019-10-08 11:05:26 -0400 |
commit | 5e9b5ec6352bee4b96cd4bbedfa17413111462b3 (patch) | |
tree | 11c1c8308e4a337b696bda257fb7996a3f9b4721 /numpy/random/tests | |
parent | d0b0c609cc614f3bc82a7cfcb98e34e939a3e8de (diff) | |
download | numpy-5e9b5ec6352bee4b96cd4bbedfa17413111462b3.tar.gz |
BUG: random: Use correct length when axis is given to shuffle.
When an axis argument was given, shuffle was using the original length of
the array instead of the length of the given axis. This meant that, for
example, if an array with shape (2, 10) was shuffled with axis=1, only the
first two columns were shuffled.
Diffstat (limited to 'numpy/random/tests')
-rw-r--r-- | numpy/random/tests/test_generator_mt19937.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/numpy/random/tests/test_generator_mt19937.py b/numpy/random/tests/test_generator_mt19937.py index 20bc10cd0..391c33c1a 100644 --- a/numpy/random/tests/test_generator_mt19937.py +++ b/numpy/random/tests/test_generator_mt19937.py @@ -746,6 +746,15 @@ class TestRandomDist(object): random.shuffle(actual, axis=-1) assert_array_equal(actual, desired) + def test_shuffle_axis_nonsquare(self): + y1 = np.arange(20).reshape(2, 10) + y2 = y1.copy() + random = Generator(MT19937(self.seed)) + random.shuffle(y1, axis=1) + random = Generator(MT19937(self.seed)) + random.shuffle(y2.T) + assert_array_equal(y1, y2) + def test_shuffle_masked(self): # gh-3263 a = np.ma.masked_values(np.reshape(range(20), (5, 4)) % 3 - 1, -1) |