Population refers to the entire set of individuals or objects of interest, while a sample is a subset of the population. To demonstrate this concept, let's assume we have a dataset called data containing the heights of 100 people. Here's an example code snippet to calculate statistics for both the population and a sample:
import numpy as np
# Assuming `data` is a numpy array containing the heights of 100 people
population_mean = np.mean(data)
population_std = np.std(data)
# Generating a random sample of size 30 from the population
sample = np.random.choice(data, size=30)
sample_mean = np.mean(sample)
sample_std = np.std(sample)
print("Population Mean:", population_mean)
print("Population Standard Deviation:", population_std)
print("Sample Mean:", sample_mean)
print("Sample Standard Deviation:", sample_std)