0
0
NumPydata~30 mins

Random sampling distributions in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Random Sampling Distributions
📖 Scenario: Imagine you are a scientist studying the heights of plants in a garden. You want to understand how the average height changes when you take different random samples from the garden.
🎯 Goal: You will create a list of plant heights, set a sample size, take many random samples from the list, calculate the average height for each sample, and finally display the list of these sample averages.
📋 What You'll Learn
Create a list called plant_heights with exact values: 10, 15, 14, 20, 18, 22, 17, 19, 16, 21
Create a variable called sample_size and set it to 4
Use a for loop to take 5 random samples of size sample_size from plant_heights using numpy.random.choice
Calculate the average height of each sample and store these averages in a list called sample_averages
Print the list sample_averages to see the results
💡 Why This Matters
🌍 Real World
Scientists and researchers often take random samples from a population to estimate average values without measuring everyone.
💼 Career
Understanding sampling distributions is important for data analysts and scientists to make predictions and decisions based on sample data.
Progress0 / 4 steps
1
Create the plant heights list
Create a list called plant_heights with these exact values: 10, 15, 14, 20, 18, 22, 17, 19, 16, 21
NumPy
Need a hint?

Use square brackets [] to create the list and separate numbers with commas.

2
Set the sample size
Create a variable called sample_size and set it to 4
NumPy
Need a hint?

Just assign the number 4 to the variable sample_size.

3
Take random samples and calculate averages
Import numpy as np. Create an empty list called sample_averages. Use a for loop with variable i running 5 times. Inside the loop, take a random sample of size sample_size from plant_heights using np.random.choice with replace=True. Calculate the average of this sample using np.mean and append it to sample_averages.
NumPy
Need a hint?

Remember to import numpy first. Use np.random.choice to pick random samples with replacement. Use np.mean to find the average.

4
Print the sample averages
Print the list sample_averages to see the average heights of the 5 random samples.
NumPy
Need a hint?

Use print(sample_averages) to show the list of averages.