Uniform Distribution

M.Ramya

 Uniform Distribution

Uniform distribution is used to describe situations where all outcomes have an equal chance of occurring. It’s commonly used for generating random numbers.

Parameters:

low – Lower boundary of the distribution (default: 0.0)

high – Upper boundary of the distribution (default: 1.0)

size – Shape of the output array (defines the number of samples).

Program:

Generate a 2x3 sample from a uniform distribution:

from numpy import random

x = random.uniform(size=(2, 3))

print(x)

Output:

[[0.62114757 0.1096391  0.73659325]
 [0.31405799 0.96172304 0.44268658]]

Visualization of Uniform Distribution

from numpy import random

import matplotlib.pyplot as plt

import seaborn as sns

sns.displot(random.uniform(size=1000), kind="kde")

plt.show()


Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send