mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +00:00
bpo-38881: choices() raises ValueError when all weights are zero (GH-17362)
This commit is contained in:
parent
84b1ff6560
commit
041d8b48a2
4 changed files with 15 additions and 3 deletions
|
|
@ -165,8 +165,9 @@ Functions for sequences
|
|||
|
||||
The *weights* or *cum_weights* can use any numeric type that interoperates
|
||||
with the :class:`float` values returned by :func:`random` (that includes
|
||||
integers, floats, and fractions but excludes decimals). Weights are
|
||||
assumed to be non-negative.
|
||||
integers, floats, and fractions but excludes decimals). Behavior is
|
||||
undefined if any weight is negative. A :exc:`ValueError` is raised if all
|
||||
weights are zero.
|
||||
|
||||
For a given seed, the :func:`choices` function with equal weighting
|
||||
typically produces a different sequence than repeated calls to
|
||||
|
|
@ -177,6 +178,9 @@ Functions for sequences
|
|||
|
||||
.. versionadded:: 3.6
|
||||
|
||||
.. versionchanged:: 3.9
|
||||
Raises a :exc:`ValueError` if all weights are zero.
|
||||
|
||||
|
||||
.. function:: shuffle(x[, random])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue