0
0
NumPydata~15 mins

np.std() and np.var() for spread in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding np.std() and np.var() for Spread
📖 Scenario: You are a data analyst working with daily temperatures recorded over a week. You want to understand how much the temperatures vary each day.
🎯 Goal: Calculate the variance and standard deviation of the temperature data using np.var() and np.std() to measure the spread of the temperatures.
📋 What You'll Learn
Create a numpy array called temperatures with the exact values: 22, 24, 19, 23, 25, 20, 21
Create a variable called ddof and set it to 0
Calculate the variance of temperatures using np.var() with ddof and store it in variance
Calculate the standard deviation of temperatures using np.std() with ddof and store it in std_dev
Print the values of variance and std_dev
💡 Why This Matters
🌍 Real World
Understanding data spread helps in weather forecasting, quality control, and risk assessment by showing how much data varies.
💼 Career
Data scientists and analysts use variance and standard deviation to summarize data variability and make informed decisions.
Progress0 / 4 steps
1
Create the temperature data array
Create a numpy array called temperatures with these exact values: 22, 24, 19, 23, 25, 20, 21
NumPy
Need a hint?

Use np.array() to create the array with the exact numbers inside square brackets.

2
Set the degrees of freedom variable
Create a variable called ddof and set it to 0
NumPy
Need a hint?

Just assign 0 to the variable ddof.

3
Calculate variance and standard deviation
Calculate the variance of temperatures using np.var() with ddof and store it in variance. Then calculate the standard deviation using np.std() with ddof and store it in std_dev.
NumPy
Need a hint?

Use np.var(temperatures, ddof=ddof) and np.std(temperatures, ddof=ddof) to calculate the spread.

4
Print the variance and standard deviation
Print the values of variance and std_dev on separate lines.
NumPy
Need a hint?

Use two print() statements, one for variance and one for std_dev.