0
0
NumPydata~10 mins

Normal distribution with normal() in NumPy - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Normal distribution with normal()
Call np.random.normal(mean, std, size)
Generate random values
Return array of values
Use values for analysis or plot
The function np.random.normal() generates random numbers following a bell-shaped curve defined by mean and standard deviation.
Execution Sample
NumPy
import numpy as np
values = np.random.normal(0, 1, 5)
print(values)
Generate 5 random numbers from a normal distribution with mean 0 and std 1, then print them.
Execution Table
StepActionParametersGenerated ValuesOutput
1Call np.random.normalmean=0, std=1, size=5N/AN/A
2Generate 5 random valuesN/A[0.5, -1.2, 0.3, 1.1, -0.7]N/A
3Return arrayN/A[0.5, -1.2, 0.3, 1.1, -0.7][0.5, -1.2, 0.3, 1.1, -0.7]
4Print valuesN/AN/A[0.5, -1.2, 0.3, 1.1, -0.7]
💡 All 5 values generated and printed, execution ends.
Variable Tracker
VariableStartAfter np.random.normal callFinal
valuesundefined[0.5, -1.2, 0.3, 1.1, -0.7][0.5, -1.2, 0.3, 1.1, -0.7]
Key Moments - 2 Insights
Why do the generated values look different each time I run the code?
Because np.random.normal generates random numbers each time, the values change on every run as shown in the execution_table rows 2 and 3.
What do the mean and std parameters control?
Mean shifts the center of the values, std controls how spread out they are. This is why in the execution_table step 1, mean=0 and std=1 define the shape of generated values.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the variable 'values' after step 2?
Aundefined
B[0.5, -1.2, 0.3, 1.1, -0.7]
CN/A
D[0, 0, 0, 0, 0]
💡 Hint
Check the 'Generated Values' column in row 2 of execution_table.
At which step does the function return the generated array?
AStep 3
BStep 2
CStep 1
DStep 4
💡 Hint
Look for the 'Return array' action in execution_table.
If we change std from 1 to 2, how would the generated values change?
AValues would all be zero
BValues would be closer to the mean
CValues would be more spread out from the mean
DValues would not change
💡 Hint
Recall std controls spread as explained in key_moments and concept_flow.
Concept Snapshot
np.random.normal(mean, std, size) generates random numbers
from a normal distribution with given mean and std deviation.
Returns an array of 'size' values.
Mean shifts center; std controls spread.
Values differ each run due to randomness.
Full Transcript
This visual execution shows how np.random.normal works step-by-step. First, the function is called with mean 0, std 1, and size 5. Then, it generates 5 random values following the bell curve shape. These values are returned as an array and printed. The variable 'values' holds these numbers after generation. The randomness means values change each run. Mean and std control the center and spread of the numbers. This helps in simulations and data analysis where normal distribution is assumed.