understanding: numpy.random.choice, numpy.random.rand, numpy.random.randint,numpy.random.shuffle,numpy.random.permutation

Generating Random Integer

numpy.random.randint(low, high=None, size=None, dtype=int)

Returns a random number from low(inclusive) to high(exclusive). low can be an Integer of Array

if high = None returns result from [0,low) else [low,high)

# array with size 12 with lower bound 0 inclusive and upper bound 2 exclusive

from numpy.random import randint
randint(2,size = 12)
Out[2]: array([1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0])
--------------------------------------------------------------------randint(1,size = 12)
Out[4]: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
--------------------------------------------------------------------
# array with lower bound 0 and upper bound 7 (exclusive)
with shape (4,5)
randint(1,size = 12)
Out[4]: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
--------------------------------------------------------------------# array with lower bound 3 and upper bound any of(4,5,6)
randint(3,[4,5,6])
Out[7]: array([3, 4, 3])

Image for post

randint([1,2,3],[[6],[7000]])
Out[16]: 
array([[   1,    3,    4],
       [5437, 3861,  417]])

Image for post

#python #artificial-intelligence #data-science #machine-learning #numpy

NumPy Random Module (numpy.random) Examples
1.70 GEEK