[Numpy-discussion] ndarray.count() ?

rex rex at nosyntax.com
Thu Sep 7 17:33:36 CDT 2006


Charles R Harris <charlesr.harris at gmail.com> [2006-09-07 15:04]:
> I don't know about count, but you can gin up something like this
> 
> In [78]: a = ran.randint(0,2, size=(10,))
> 
> In [79]: a
> Out[79]: array([0, 1, 0, 1, 1, 0, 0, 1, 1, 1])

This exposed inconsistent randint() behavior between SciPy and the Python
random module. The Python randint includes the upper endpoint. The SciPy
version excludes it.

>>> from random import randint
>>> for i in range(50):
...   print randint(0,2),
...
0 1 1 1 1 1 0 0 2 1 1 0 2 2 1 2 0 2 0 0 0 2 2 2 2 2 2 2 1 2 2 0 0 1 2 2 0 1 1 0 2 0 1 2 1 2 2 2 1 1

>>> from scipy import *

>>> print random.randint(0,2, size=(100,))
[0 1 1 1 1 0 1 1 0 1 0 0 0 0 0 1 0 1 1 0 1 0 1 0 0 0 1 0 0 0 1 1 1 1 0 1 1
 1 0 0 0 1 1 0 0 0 1 0 1 0 0 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 1 0 0 1 0 1 1 0
 0 0 0 1 1 1 1 1 0 1 1 0 0 1 1 1 1 1 1 0 1 1 1 1 0 0]

-rex




More information about the Numpy-discussion mailing list