🔥Limited Offer: Get 50% OFFon AI & Full Stack Courses🔥
Back to NumPy Notes
Topic #18

Data Distribution


What is Data Distribution?

Data Distribution is a list of all possible values, and how often each value occurs.

Such lists are important when working with statistics and data science.

The random module offer methods that returns randomly generated data distributions.


Random Distribution

A random distribution is a set of random numbers that follow a certain probability density function.

Note: Probability Density Function: A function that describes a continuous probability. i.e. probability of all values in an array.

We can generate random numbers based on defined probabilities using the choice() method of the random module.

The choice() method allows us to specify the probability for each value.

The probability is set by a number between 0 and 1, where 0 means that the value will never occur and 1 means that the value will always occur.

Example

  from numpy import random

x = random.choice([3, 5, 7, 9], p=[0.1, 0.3,
  0.6, 0.0], size=(100))

print(x)

Note: The sum of all probability numbers should be 1.

Even if you run the example above 100 times, the value 9 will never occur.

You can return arrays of any shape and size by specifying the shape in the size parameter.

Example

  from numpy import random

x = random.choice([3, 5, 7, 9], p=[0.1, 0.3,
  0.6, 0.0], size=(3, 5))

print(x)

Want to go beyond the notes?

Join CodingNow 2.0's NumPy course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Data Distribution – FAQs

Quick answers about learning Data Distribution in NumPy.

This free note from CodingNow 2.0 explains Data Distribution in NumPy — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every NumPy topic on CodingNow 2.0, including Data Distribution, is 100% free with no signup required.
With focused practice, most students grasp Data Distribution in 1–3 days from these notes; pairing it with CodingNow 2.0's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the CodingNow 2.0 Community (/community) — expert instructors answer within 24 hours.
WhatsApp
Call NowEnroll Now