138
138
np.random.seed(self.seed)
139
139
actual = np.random.choice(4, 3, replace=False,
140
140
p=[0.1, 0.3, 0.5, 0.1])
141
desired = np.array([2, 1, 3])
141
desired = np.array([2, 3, 1])
142
142
np.testing.assert_array_equal(actual, desired)
144
144
def test_choice_noninteger(self):
161
161
assert_raises(ValueError, sample, [1,2,3], 2, replace=False,
164
def test_choice_return_shape(self):
167
assert_(np.isscalar(np.random.choice(2, replace=True)))
168
assert_(np.isscalar(np.random.choice(2, replace=False)))
169
assert_(np.isscalar(np.random.choice(2, replace=True, p=p)))
170
assert_(np.isscalar(np.random.choice(2, replace=False, p=p)))
171
assert_(np.isscalar(np.random.choice([1,2], replace=True)))
175
assert_(not np.isscalar(np.random.choice(2, s, replace=True)))
176
assert_(not np.isscalar(np.random.choice(2, s, replace=False)))
177
assert_(not np.isscalar(np.random.choice(2, s, replace=True, p=p)))
178
assert_(not np.isscalar(np.random.choice(2, s, replace=False, p=p)))
179
assert_(not np.isscalar(np.random.choice([1,2], s, replace=True)))
181
# Check multi dimensional array
183
p = [0.1, 0.1, 0.1, 0.1, 0.4, 0.2]
184
assert_(np.random.choice(6, s, replace=True).shape, s)
185
assert_(np.random.choice(6, s, replace=False).shape, s)
186
assert_(np.random.choice(6, s, replace=True, p=p).shape, s)
187
assert_(np.random.choice(6, s, replace=False, p=p).shape, s)
188
assert_(np.random.choice(np.arange(6), s, replace=True).shape, s)
164
190
def test_bytes(self):
165
191
np.random.seed(self.seed)
166
192
actual = np.random.bytes(10)