0
0
NumPydata~15 mins

Generating random samples in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Generating Random Samples with NumPy
📖 Scenario: Imagine you are a data scientist working on a project where you need to simulate data for testing. You want to create random samples from a normal distribution to mimic real-world measurements.
🎯 Goal: Learn how to generate random samples using NumPy's random module and display the generated data.
📋 What You'll Learn
Create a NumPy array of random samples from a normal distribution
Set the mean and standard deviation for the distribution
Generate a specific number of samples
Print the generated samples
💡 Why This Matters
🌍 Real World
Generating random samples is useful for simulating data when real data is not available or for testing algorithms.
💼 Career
Data scientists often need to create synthetic data to test models or understand statistical properties.
Progress0 / 4 steps
1
Import NumPy and set up sample size
Import the numpy library as np and create a variable called sample_size with the value 10.
NumPy
Need a hint?

Use import numpy as np to import NumPy. Then create sample_size = 10.

2
Set mean and standard deviation
Create two variables: mean with value 0 and std_dev with value 1 to represent the mean and standard deviation of the normal distribution.
NumPy
Need a hint?

Set mean = 0 and std_dev = 1.

3
Generate random samples
Use np.random.normal with parameters mean, std_dev, and sample_size to create a variable called samples that holds the random samples.
NumPy
Need a hint?

Call np.random.normal(mean, std_dev, sample_size) and assign it to samples.

4
Print the generated samples
Print the variable samples to display the generated random numbers.
NumPy
Need a hint?

Use print(samples) to show the array of random numbers.