Bird
Raised Fist0
NumPydata~5 mins

Normal distribution with normal() in NumPy - Cheat Sheet & Quick Revision

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the numpy.random.normal() function do?
It generates random numbers that follow a normal (bell-shaped) distribution, centered around a mean value with a given spread (standard deviation).
Click to reveal answer
beginner
What are the main parameters of numpy.random.normal()?
The main parameters are loc (mean), scale (standard deviation), and size (number of values to generate).
Click to reveal answer
beginner
Why is the standard deviation important in a normal distribution?
Standard deviation controls how spread out the numbers are around the mean. A small value means numbers are close to the mean; a large value means they are more spread out.
Click to reveal answer
beginner
How can you generate 1000 random numbers with mean 10 and standard deviation 2 using numpy?
Use numpy.random.normal(loc=10, scale=2, size=1000) to get 1000 numbers centered at 10 with spread 2.
Click to reveal answer
intermediate
What shape of data does numpy.random.normal() return when size is a tuple?
It returns a NumPy array with the shape given by the tuple, filled with random numbers from the normal distribution.
Click to reveal answer
What does the loc parameter in numpy.random.normal() specify?
AThe number of samples to generate
BThe mean of the distribution
CThe standard deviation of the distribution
DThe minimum value of the distribution
If you want to generate 500 random numbers from a normal distribution, which parameter controls this?
Aloc
Bscale
Csize
Dmean
What happens if you set scale=0 in numpy.random.normal()?
AYou get random numbers spread out widely
BYou get negative numbers only
CYou get an error
DYou get all numbers equal to the mean
Which shape will the output have if you use size=(3,4)?
AA 3 by 4 NumPy array
BA list of 12 numbers
CA single number
DA 4 by 3 NumPy array
Which of these is true about the normal distribution?
AIt is symmetric around the mean
BIt has no mean
CIt only produces positive numbers
DIt is always skewed to the right
Explain how to use numpy.random.normal() to simulate real-world data like heights or test scores.
Think about how average and spread describe real data.
You got /5 concepts.
    Describe the effect of changing the scale parameter on the shape of the data generated by numpy.random.normal().
    Consider what happens when spread increases or decreases.
    You got /4 concepts.

      Practice

      (1/5)
      1. What does the loc parameter control in the numpy.random.normal() function?
      easy
      A. The spread (standard deviation) of the normal distribution
      B. The center (mean) of the normal distribution
      C. The number of random values generated
      D. The shape of the distribution curve

      Solution

      1. Step 1: Understand the parameters of normal()

        The normal() function has parameters loc and scale. loc sets the mean (center) of the distribution.
      2. Step 2: Identify the role of loc

        The mean is the center point where most values cluster in a bell curve.
      3. Final Answer:

        The center (mean) of the normal distribution -> Option B
      4. Quick Check:

        loc = center [OK]
      Hint: Remember: loc = center, scale = spread [OK]
      Common Mistakes:
      • Confusing loc with scale
      • Thinking loc controls number of samples
      • Assuming loc changes distribution shape
      2. Which of the following is the correct syntax to generate 5 random numbers from a normal distribution with mean 10 and standard deviation 2 using numpy?
      easy
      A. numpy.random.normal(size=5, mean=10, std=2)
      B. numpy.normal(10, 2, 5)
      C. numpy.random.normal(5, loc=10, scale=2)
      D. numpy.random.normal(loc=10, scale=2, size=5)

      Solution

      1. Step 1: Recall the correct function and parameters

        The function is numpy.random.normal() with parameters loc for mean, scale for std dev, and size for number of samples.
      2. Step 2: Match parameters to correct syntax

        numpy.random.normal(loc=10, scale=2, size=5) correctly uses loc=10, scale=2, and size=5.
      3. Final Answer:

        numpy.random.normal(loc=10, scale=2, size=5) -> Option D
      4. Quick Check:

        Correct parameter names and order [OK]
      Hint: Use loc=mean, scale=std, size=number [OK]
      Common Mistakes:
      • Using wrong parameter names like mean or std
      • Mixing order without keywords
      • Calling numpy.normal instead of numpy.random.normal
      3. What is the output shape of the following code?
      import numpy as np
      arr = np.random.normal(loc=0, scale=1, size=(3,4))
      print(arr.shape)
      medium
      A. (12,)
      B. (4, 3)
      C. (3, 4)
      D. (3,)

      Solution

      1. Step 1: Understand the size parameter

        The size argument is set to (3,4), which means generate a 2D array with 3 rows and 4 columns.
      2. Step 2: Check the shape of the generated array

        Printing arr.shape returns the shape tuple, which matches the size argument.
      3. Final Answer:

        (3, 4) -> Option C
      4. Quick Check:

        size=(3,4) means shape=(3,4) [OK]
      Hint: size tuple = output shape [OK]
      Common Mistakes:
      • Confusing rows and columns order
      • Expecting flattened array shape
      • Ignoring tuple format for size
      4. Identify the error in this code snippet:
      import numpy as np
      samples = np.random.normal(mean=0, std=1, size=10)
      print(samples)
      medium
      A. Incorrect parameter names: should use loc and scale instead of mean and std
      B. Missing import statement for numpy
      C. size parameter must be a tuple, not an integer
      D. The print statement syntax is wrong

      Solution

      1. Step 1: Check parameter names for normal()

        The function np.random.normal() expects loc for mean and scale for standard deviation, not mean or std.
      2. Step 2: Verify other parts of the code

        Import is correct, size can be integer, and print syntax is valid.
      3. Final Answer:

        Incorrect parameter names: should use loc and scale instead of mean and std -> Option A
      4. Quick Check:

        Use loc and scale for mean and std [OK]
      Hint: Use loc=mean, scale=std; mean/std are invalid [OK]
      Common Mistakes:
      • Using mean or std instead of loc and scale
      • Thinking size must be tuple always
      • Assuming print syntax error
      5. You want to simulate daily temperatures for a week that average 20°C with a standard deviation of 3°C. Which code correctly generates this data and calculates the average temperature?
      hard
      A. temps = np.random.normal(loc=20, scale=3, size=7) avg_temp = temps.mean() print(round(avg_temp, 2))
      B. temps = np.random.normal(mean=20, std=3, size=7) avg_temp = temps.sum() print(avg_temp)
      C. temps = np.random.normal(loc=3, scale=20, size=7) avg_temp = temps.mean() print(avg_temp)
      D. temps = np.random.normal(loc=20, scale=3, size=7) avg_temp = temps.median() print(avg_temp)

      Solution

      1. Step 1: Generate temperatures with correct parameters

        Use loc=20 for mean temperature and scale=3 for standard deviation, with size=7 for a week.
      2. Step 2: Calculate the average temperature correctly

        Use temps.mean() to get the average. Round for neat output.
      3. Final Answer:

        temps = np.random.normal(loc=20, scale=3, size=7) avg_temp = temps.mean() print(round(avg_temp, 2)) -> Option A
      4. Quick Check:

        loc=mean, scale=std, mean() for average [OK]
      Hint: Use loc=mean, scale=std, mean() to average [OK]
      Common Mistakes:
      • Swapping loc and scale values
      • Using mean or std instead of loc and scale
      • Using sum() instead of mean() for average
      • Using median() instead of mean()