Site icon DataFlair

Random Distribution in NumPy

Machine Learning courses with 110+ Real-time projects Start Now!!

Program 1

#Random Distribution in Numpy
#Random distribution is a set of random numbers that follow a certain probability density function.

# Create a 1-D array which contain 50 values, where each value has to be 5, 10, 12 or 15.

# The probability for the value to be 5 is set to be 0.1

# The probability for the value to be 10 is set to be 0.3

# The probability for the value to be 12 is set to be 0.6

# The probability for the value to be 15 is set to be 0

from numpy import random

# myar=random.choice([5,10,12,15],p=[0.1,0.3,0.6,0.0],size=(2,3,3))
# print(myar)

toss=random.choice([0,1,0,1],p=[0.1,0.3,0.6,0.0],size=(1))
if(toss==0):
    print("HEAD")
else:
    print("TAIL")














# myar=random.choice([5,10,12,15],p=[0.1, 0.3, 0.6,0.0],size=(3,3,2))
# print(myar)
# print(type(myar))




# from numpy import random
# myar=random.choice([0,1,1,0],p=[0.1, 0.3, 0.6,0.0],size=(1))
# if(myar.sum()==1):
#     print("Head")
# else:
#     print("Tail")

 

Exit mobile version