A note I was addicted to with Python's randint. There are random.randint and numpy.random.randint as functions that return random integers within a certain interval, but these are actually different specifications.
Take a look at the documentation. First from random.randint
randint(self, a, b) method of random.Random instance Return random integer in range [a, b], including both end points.
Then numpy.random.randint
randint(low, high=None, size=None)
Return random integers from
low
(inclusive) tohigh
(exclusive).Return random integers from the "discrete uniform" distribution in the "half-open" interval [
low
,high
). Ifhigh
is None (the default), then results are from [0,low
).
In other words, random.randint (a, b) may return an integer from a to b (including b), and numpy.random.randint (a, b) may return an integer from a to b-1. There is a possibility that it will come back.
What the hell is that! confusing!
I think the latter is the more natural specification. For example, range (1,5) returns [1,2,3,4].
Then, Happy Halloween and Happy Hacking!
Recommended Posts