[Numpy-discussion] making "low" optional in numpy.randint

Sebastian Berg sebastian at sipsolutions.net
Wed Feb 17 16:10:29 EST 2016


On Mi, 2016-02-17 at 20:48 +0000, Robert Kern wrote:
> On Wed, Feb 17, 2016 at 8:43 PM, G Young <gfyoung17 at gmail.com> wrote:
> 
> > Josef: I don't think we are making people think more.  They're all
> keyword arguments, so if you don't want to think about them, then you
> leave them as the defaults, and everyone is happy. 
> 
> I believe that Josef has the code's reader in mind, not the code's
> writer. As a reader of other people's code (and I count 6-months-ago
> -me as one such "other people"), I am sure to eventually encounter
> all of the different variants, so I will need to know all of them.
> 

Completely agree. Greg, if you need more then a few minutes to explain
it in this case, there seems little point. It seems to me even the
worst cases of your examples would be covered by writing code like:

np.random.randint(np.iinfo(np.uint8).min, 10, dtype=np.uint8)

And *everyone* will immediately know what is meant with just minor
extra effort for writing it. We should keep the analogy to "range" as
much as possible. Anything going far beyond that, can be confusing. On
first sight I am not convinced that there is a serious convenience gain
by doing magic here, but this is a simple case:

"Explicit is better then implicit"

since writing the explicit code is easy. It might also create weird
bugs if the completely unexpected (most users would probably not even
realize it existed) happens and you get huge numbers because you
happened to have a `low=0` in there. Especially your point 2) seems
confusing. As for 3) if I see `np.random.randint(high=3)` I think I
would assume [0, 3)....

Additionally, I am not sure the maximum int range is such a common need
anyway?

- Sebastian


> --
> Robert Kern
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20160217/d88960d4/attachment.sig>


More information about the NumPy-Discussion mailing list