Skip to content

Commit 0799ab9

Browse files
authored
Merge pull request numpy#15138 from bashtage/more-choice-doc
DOC: Correct documentation in choice
2 parents 53a0cac + 0fd2e0b commit 0799ab9

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

numpy/random/_generator.pyx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ cdef class Generator:
224224
capsule = bit_generator.capsule
225225
cdef const char *name = "BitGenerator"
226226
if not PyCapsule_IsValid(capsule, name):
227-
raise ValueError("Invalid bit generator'. The bit generator must "
227+
raise ValueError("Invalid bit generator. The bit generator must "
228228
"be instantiated.")
229229
self._bitgen = (<bitgen_t *> PyCapsule_GetPointer(capsule, name))[0]
230230
self.lock = bit_generator.lock
@@ -635,26 +635,26 @@ cdef class Generator:
635635
636636
Parameters
637637
----------
638-
a : 1-D array-like or int
638+
a : {array_like, int}
639639
If an ndarray, a random sample is generated from its elements.
640-
If an int, the random sample is generated as if a were np.arange(a)
641-
size : int or tuple of ints, optional
640+
If an int, the random sample is generated from np.arange(a).
641+
size : {int, tuple[int]}, optional
642642
Output shape. If the given shape is, e.g., ``(m, n, k)``, then
643643
``m * n * k`` samples are drawn from the 1-d `a`. If `a` has more
644644
than one dimension, the `size` shape will be inserted into the
645645
`axis` dimension, so the output ``ndim`` will be ``a.ndim - 1 +
646646
len(size)``. Default is None, in which case a single value is
647647
returned.
648-
replace : boolean, optional
648+
replace : bool, optional
649649
Whether the sample is with or without replacement
650-
p : 1-D array-like, optional
650+
p : 1-D array_like, optional
651651
The probabilities associated with each entry in a.
652652
If not given the sample assumes a uniform distribution over all
653653
entries in a.
654654
axis : int, optional
655655
The axis along which the selection is performed. The default, 0,
656656
selects by row.
657-
shuffle : boolean, optional
657+
shuffle : bool, optional
658658
Whether the sample is shuffled when sampling without replacement.
659659
Default is True, False provides a speedup.
660660
@@ -725,13 +725,15 @@ cdef class Generator:
725725
# __index__ must return an integer by python rules.
726726
pop_size = operator.index(a.item())
727727
except TypeError:
728-
raise ValueError("a must be 1-dimensional or an integer")
728+
raise ValueError("a must an array or an integer")
729729
if pop_size <= 0 and np.prod(size) != 0:
730-
raise ValueError("a must be greater than 0 unless no samples are taken")
730+
raise ValueError("a must be a positive integer unless no"
731+
"samples are taken")
731732
else:
732733
pop_size = a.shape[axis]
733734
if pop_size == 0 and np.prod(size) != 0:
734-
raise ValueError("'a' cannot be empty unless no samples are taken")
735+
raise ValueError("a cannot be empty unless no samples are"
736+
"taken")
735737

736738
if p is not None:
737739
d = len(p)
@@ -746,9 +748,9 @@ cdef class Generator:
746748
pix = <double*>np.PyArray_DATA(p)
747749

748750
if p.ndim != 1:
749-
raise ValueError("'p' must be 1-dimensional")
751+
raise ValueError("p must be 1-dimensional")
750752
if p.size != pop_size:
751-
raise ValueError("'a' and 'p' must have same size")
753+
raise ValueError("a and p must have same size")
752754
p_sum = kahan_sum(pix, d)
753755
if np.isnan(p_sum):
754756
raise ValueError("probabilities contain NaN")
@@ -770,13 +772,14 @@ cdef class Generator:
770772
cdf /= cdf[-1]
771773
uniform_samples = self.random(shape)
772774
idx = cdf.searchsorted(uniform_samples, side='right')
773-
idx = np.array(idx, copy=False, dtype=np.int64) # searchsorted returns a scalar
775+
# searchsorted returns a scalar
776+
idx = np.array(idx, copy=False, dtype=np.int64)
774777
else:
775778
idx = self.integers(0, pop_size, size=shape, dtype=np.int64)
776779
else:
777780
if size > pop_size:
778781
raise ValueError("Cannot take a larger sample than "
779-
"population when 'replace=False'")
782+
"population when replace is False")
780783
elif size < 0:
781784
raise ValueError("negative dimensions are not allowed")
782785

0 commit comments

Comments
 (0)