Feature request: Set replace flag with tuple for nd array
See original GitHub issueTo be able to vectorise random sampling with/without replacement is would be useful to be able to set the replace
flag in random.choice
to a tuple matching the shape of size
. i.e.
# THIS IS NOT A WORKING CODE
from numpy import np
x = [i for i in range(100)]
k = np.random.poission(0.5, 10)
samples = np.random.choice(x, size=(10, 10), replace=(False, True), p=k)
This would allow for a much neater way to produce a 2D array where each row is a sample from the same population taken without replacement.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (9 by maintainers)
Top Results From Across the Web
The tuple built-in is not supported in nopython mode #2771
The tuple([iterable]) python built-in function doesn't work in nopython mode. Is there any plan to support this in nopython mode?
Read more >Documentation - TypeScript 4.0
Variadic Tuple Types. Consider a function in JavaScript called concat that takes two array or tuple types and concatenates them together to make...
Read more >numpy.ndarray.flags — NumPy v1.24 Manual
Only the WRITEBACKIFCOPY, WRITEABLE, and ALIGNED flags can be changed by the user, via direct assignment to ... The array flags cannot be...
Read more >Typed Memoryviews — Cython 3.0.0a11 documentation
Memoryviews are similar to the current NumPy array buffer support ( np.ndarray[np.float64_t, ndim=2] ), but they have more features and cleaner syntax.
Read more >Difference between numpy.array shape (R, 1) and (R,)
A tuple is not determined by the parentheses, they are not part of it, but by the comma. x=4, assigns a tuple, x=(4)...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m not a huge fan of the proposed spelling, but agreed that the feature itself makes sense.
If it really needed to go into choice I would suggest something like:
With this API, your call would be
and each row would be an independent sample.
You could also do things like
which would produce an output that is (100, 100, 2, 2) which is 10,000 independent samples of 2 by 2 choice.