-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
random_choice()
returns a numpy array, is this by design?
#199
Comments
The https://ixora.io/blog/new-release-081a1/ I seem to remember this change was prompted by a discussion with you but I can't find it on github. Perhaps it was through Twitter DMs? In any case, if the size param is 2 or more, the result needs to be a numpy array (or at least a collection of some kind). If size param is 1, returning anything other than a numpy array would mean that the type of the returned result depends on the size param, which is a bit odd. This is also consistent with what But on the other hand, I can see your point, it is also odd to return a numpy array with one item in it, and that is most likely not what a user would expect or want when using this method. Which way do you think is better? It wouldn't be difficult to check the result and if it is just one item, return the one item and not leave it in a numpy array. |
It was a Twitter DM, from back in July. You wanted to take random samples of different sizes and I upgraded the random_choice() method to accommodate that. By design, it is consistent with what numpy does. I should check to see what py5's random_choice() did before that release. Before then it would only return 1 item and I bet it did not return that 1 item in an array like it does now. How about changing random_choice() to be how it was before and making a new method random_sample() that let you pick the sample size? The random_choice() method would only return 1 thing without an array and random_sample() would always return an array, of size 1 or more, depending on the size param. So basically I am suggesting we rename the current random_choice() method random_sample() and then make a new random_choice() method that works the way it did before, returning just one item and that's it. |
Perfect! As I was reading, I was going to suggest a |
Technically you already did, back in July! But then I interfered with that idea and combined it with the existing random_choice() method to make something that was not as nice. |
This is done. I opened an issue to py5book so we remember to update summary.md to reflect the changes. |
I was not expecting this...
result:
The text was updated successfully, but these errors were encountered: