Loading...
Loading...
Calculate weighted mean for grades, GPA, portfolios, and more. Step-by-step solution with Python code.
| Label | Value | Weight | |
|---|---|---|---|
| Item | Value (xᵢ) | Weight (wᵢ) | wᵢ × xᵢ | Contribution |
|---|---|---|---|---|
| Homework | 92 | 20 | 1840 | 21.3% |
| Midterm | 85 | 30 | 2550 | 29.5% |
| Project | 95 | 20 | 1900 | 22% |
| Final Exam | 78 | 30 | 2340 | 27.1% |
| Total | 100 | 8630 | 100% |
import numpy as np
# Data
values = np.array([92, 85, 95, 78])
weights = np.array([20, 30, 20, 30])
labels = ["Homework", "Midterm", "Project", "Final Exam"]
# Weighted average
weighted_avg = np.average(values, weights=weights)
print(f"Weighted Average: {weighted_avg:.4f}")
# Simple average for comparison
simple_avg = np.mean(values)
print(f"Simple Average: {simple_avg:.4f}")
# Weighted variance and std dev
weighted_var = np.average((values - weighted_avg) ** 2, weights=weights)
weighted_std = np.sqrt(weighted_var)
print(f"Weighted Std Dev: {weighted_std:.4f}")
# Contribution of each item
products = values * weights
total_product = np.sum(products)
contributions = products / total_product * 100
print("\nBreakdown:")
print(f"{'Item':<12} {'Value':>8} {'Weight':>8} {'Product':>10} {'Contrib':>8}")
print("-" * 50)
for lbl, v, w, p, c in zip(labels, values, weights, products, contributions):
print(f"{lbl:<12} {v:>8.2f} {w:>8.2f} {p:>10.2f} {c:>7.1f}%")
print("-" * 50)
print(f"{'Total':<12} {'':>8} {np.sum(weights):>8.2f} {total_product:>10.2f} {'100.0':>7}%")A weighted average is a mean where each value contributes proportionally to its assigned weight. Unlike a simple average where all values count equally, a weighted average gives more importance to values with higher weights. Formula: Σ(wᵢ × xᵢ) / Σ(wᵢ).
Use a weighted average when values have unequal importance: course grades with different credit hours, portfolio returns with different asset allocations, survey responses with different sample sizes, or any scenario where some data points should count more than others.
No. Weights can be any positive numbers - they are automatically normalized by dividing by the sum of weights. Whether you use 1:2:3, 10:20:30, or 0.1:0.2:0.3, you get the same weighted average.
Multiply each course grade point (e.g., A=4.0) by its credit hours, sum the products, then divide by total credit hours. For example: (4.0×3 + 3.0×4 + 3.7×3) / (3+4+3) = 3.51 GPA.
The weighted average sums weighted values divided by total weight, while the weighted median is the value where cumulative weight reaches 50%. The weighted median is more robust to outliers, similar to how the regular median resists extreme values.