8000 np.random.choice(0, size=0) fails · Issue #10597 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

np.random.choice(0, size=0) fails #10597

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
girving opened this issue Feb 15, 2018 · 2 comments
Closed

np.random.choice(0, size=0) fails #10597

girving opened this issue Feb 15, 2018 · 2 comments

Comments

@girving
Copy link
Contributor
girving commented Feb 15, 2018

np.random.choice requires the upper limit a > 0:

>>> np.random.choice(0, size=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mtrand.pyx", line 1120, in mtrand.RandomState.choice
ValueError: a must be greater than 0

This is necessary if size > 0, but if size == 0 we could permit this special case. Allowing the valid special case would simplify certain code, and in particular would make np.random.choice(limit, size=min(n, limit) always work. The same goes for np.random.randint:

>>> np.random.randint(0, size=0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mtrand.pyx", line 993, in mtrand.RandomState.randint
ValueError: low >= high
@eric-wieser
Copy link
Member

See #8717

@girving
Copy link
Contributor Author
girving commented Feb 16, 2018

@eric-wieser Yikes! It sounded so simple...

Duplicate of #8311.

@girving girving closed this as completed Feb 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0