Random Data Distribution in NumPy

Machine Learning courses with 100+ 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")

 

Your opinion matters
Please write your valuable feedback about DataFlair on Google

courses
Image

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *