numpy random rand code example

Example 1: random array numpy

>>> np.random.rand(3,2)
array([[ 0.14022471,  0.96360618],  
       [ 0.37601032,  0.25528411],  
       [ 0.49313049,  0.94909878]]) 

>>> np.random.random_integers(low=0, high=9, size=(3,2))
array([[2, 3],
       [2, 3],
       [6, 3]])

Example 2: numpy random int

np.random.randint(2, size=10) # Creates binary sample of size 10
np.random.randint(5, size=10) # Creates sample with 0-4 as values of size 10

np.random.randint(5, size=(2, 4))

Example 3: random matrix python

np.random.rand(3,2)

Example 4: numpy generate random 2d array

import numpy as np
a=np.random.rand(3,3)
print(a)

Example 5: numpy randint

>>> np.random.randint(2, size=10)
array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0]) # random
>>> np.random.randint(1, size=10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

Example 6: Random Numbers in NumPy

from numpy import random

x = random.randint(100)

print(x)