This preview shows how code will appear with your selected theme.
Try changing themes to see the difference.
Python
def calculate_statistics(data):
"""Calculate mean and variance from dataset."""
n = len(data)
mean = sum(data) / n
variance = sum((x - mean) ** 2 for x in data) / n
return {
'mean': mean,
'variance': variance,
'std_dev': variance ** 0.5
}
# Example usage
dataset = [1.2, 2.5, 3.7, 4.1, 5.9]
stats = calculate_statistics(dataset)
print(f"Mean: {stats['mean']:.2f}")