[Numpy-discussion] numpy.random.randint() inconsistent with plain random.randint()

Christopher Kerr gingekerr at gmail.com
Mon Feb 25 15:58:24 EST 2008


I don't know if this is the right place to report bugs, but I couldn't find
anywhere else on the website...

random.randint(min,max) from python core returns an integer between min and
max inclusive. The documentation on the website says that
numpy.random.randint(min,max [,size]) does this too, but it in fact only
ever returns numbers strictly less than the max, and gives an error if min
is equal to max



Python 2.4.4 (#1, Dec 20 2007, 08:43:49)
[GCC 4.1.2 20070214 (  (gdc 0.24, using dmd 1.020)) (Gentoo 4.1.2 p1.0.2)]
on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import random
>>> import numpy.random
>>> numpy.version.version
'1.0.4'
>>> random.randint(3,3)
3
>>> numpy.random.randint(3,3)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "mtrand.pyx", line 600, in mtrand.RandomState.randint
ValueError: low >= high
>>> numpy.random.randint(1,3,(2,10))
array([[2, 1, 2, 1, 2, 1, 2, 1, 2, 1],
       [1, 2, 1, 2, 1, 1, 1, 2, 1, 2]])




More information about the NumPy-Discussion mailing list