TL;DR
A weighted average combines several values into one number, giving each value a share that matches its weight. A value with weight 3 counts three times as much as a value with weight 1. It solves the problem that an ordinary average treats every item as equally important, which is often wrong: a 3-credit course should count more than a 1-credit course, and a large purchase should count more than a small one.
Builds on: Summation Notation · Leads to: the mean and variance, expected value
Where it's used
Course grades. A student's grade point average (GPA) is a weighted average of the grade points earned in each course, with each course's credit hours as the weight. A four-credit course with a poor grade pulls the GPA down more than a one-credit course with the same grade, which matches how much work each course is.
Buying in bulk at different prices. A shop may buy 10 kilograms of flour at 2 dollars per kilogram in one order and 30 kilograms at 3 dollars per kilogram in another. The average price paid per kilogram is dollars, weighted by the quantities. Averaging the two prices evenly would give 2.50 dollars, which understates the cost because most of the flour was bought at 3 dollars. Accountants use this to value stock held at different costs.
Combining survey results. When a national poll reports the share of people who support a policy, a weighted average of regional results with each region weighted by its population gives a national figure. For example, region A has 1 million people with 60 percent support and region B has 3 million with 40 percent. The weighted figure is percent, while the unweighted average is 50 percent, which gives the small region the same influence as the large one. Surveys often correct for unequal selection with inverse probability weighting.
Attention in language models. In a transformer, each output vector is a weighted average of the value vectors in the sequence. The weights come from a Softmax that turns scores into positive shares adding to 1, so the most relevant tokens pull the output most. This is the normalised-weight form used in the math section.
How it works
Take two quiz scores, 80 and 60. The first quiz is worth weight 1, and the exam is worth weight 3, because the exam counts three times as much.
- Write each value with its weight. Quiz: value 80, weight 1. Exam: value 60, weight 3.
- Multiply each value by its weight. Quiz: . Exam: . Check: these are the weighted contributions of the two scores.
- Add the contributions. This is the sum that the summation sign in summation notation stands for: .
- Add the weights. . Check: the weights say the total importance is 4 units.
- Divide the total contribution by the total weight. . The weighted average is 65.
- Compare with the ordinary mean, . The weighted average is lower, because the exam with the lower score has the bigger weight. The result sits closer to 60 than to 80, which is where the weight is.
The picture is a balance. Each value is a weight placed at a point on a line, and the average is where the line balances.
flowchart LR
A[Values and weights] --> B[Multiply each value by its weight]
B --> C[Add the products]
A --> D[Add the weights]
C --> E[Divide the sum of products by the sum of weights]
D --> E
E --> F[Weighted average]
The diagram shows the two sums that every weighted average needs: a sum of products on top, and a sum of weights below.
The math
Let there be values with weights , where each and at least one weight is positive. The weighted average is written .
Step 5 in symbols: the definition
The numerator is the sum of the products in step 2 and the denominator is the sum of the weights in step 4. Check with the example: .
Step 4 in symbols: normalised weights
Divide each weight by the total weight to get shares . The shares are non-negative and add to 1:
Check: the shares are and , which add to 1. Then . This is the same answer, and it is the form used in expected value, where the shares are probabilities of the outcomes of a random variable.
Two special cases
If every weight is equal, say for all , the constant cancels and the formula becomes the ordinary mean:
If one weight is zero, its value drops out completely. Check: with weights 0 and 1 on the values 10 and 20, the result is .
Worked examples
Two values, 2 and 4, have weights 1 and 3.
- Multiply: and .
- Add the products: .
- Add the weights: .
- Divide: .
Answer: the weighted average is 3.5. The ordinary average would be 3, and the answer is pulled toward 4 because 4 has three times the weight.
A student takes three courses. The grade points are 4 (an A), 3 (a B) and 2 (a C), and the credit hours are 3, 4 and 3.
- Treat the grade points as the values and the credit hours as the weights.
- Multiply each grade point by its credits: , , .
- Add the products: .
- Add the credit hours: .
- Divide: .
- Check the result by reasoning: 3.0 lies between the grade points 2 and 4, and it is closer to 3, which is the grade of the course with the most credits (4). The GPA is 3.0.
Answer: the GPA is 3.0. The two 3-credit courses count equally and the 4-credit B course counts most, so the answer is set by the credits, not by the number of courses.
A bakery buys flour in two orders. The first is 5 kilograms at 4 dollars per kilogram. The second is 15 kilograms at 6 dollars per kilogram. The owner wants to know the average price paid per kilogram across both orders.
- The values are the prices (4 and 6 dollars per kilogram). The weights are the quantities (5 and 15 kilograms).
- Multiply each price by its quantity to get the total spent on each order: dollars and dollars.
- Add the totals: dollars spent.
- Add the quantities: kilograms bought.
- Divide: dollars per kilogram.
- Check: the simple average of the two prices is dollars, which is too low, because most of the flour was bought at 6 dollars. The weighted answer of 5.5 is closer to 6, as it should be.
Answer: the average price paid is 5.5 dollars per kilogram. The owner's real cost is the total spent divided by the total bought, which is exactly the weighted average.
Try it: a shop sells 8 kilograms of rice at 3 dollars per kilogram and 12 kilograms at 5 dollars per kilogram. What is the average price per kilogram across the whole sale? Answer: the total spent is dollars for 20 kilograms, so the average is dollars per kilogram.
Common mistakes and tradeoffs
It is tempting to think a weighted average is the average of the weights times the average of the values; in fact it is the sum of products divided by the sum of weights. Multiplying the two averages gives a different number in general, so use the definition from step 5 instead.
It is tempting to divide by the number of values when the weights are not equal; in fact you divide by the sum of the weights. Dividing by the count, as in the GPA example, gives 30 over 3 courses, which is 10 and not a grade at all.
It is tempting to average averages: take the mean of a mean of groups and call it the overall mean. In fact the overall mean needs the group sizes as weights. Two classes with averages 70 and 90 and sizes 10 and 30 have an overall average of , not 80.
Use a weighted average when the values differ in how much they should count: credits, quantities, populations, or probabilities. Use the ordinary mean when every value counts the same. For values that multiply, such as growth factors, the geometric mean is the right average instead. An alternative is to report the values and their weights together as a table, which is clearer when a reader may want to check the weights themselves. Weighted averages can hide an outlier that has a small weight, so check the individual values before trusting the single number.
History
Averages with weights are as old as trade. Merchants mixing goods of different prices or quality used them long before they had a name, and insurers and tax assessors used them to combine different records. The idea became a formal tool in the early 1800s, when weighted least squares, a form of linear regression, came into use in astronomy and surveying: observations of different precision were given different weights so that the most precise ones counted most. The same weighted sum later became the definition of expected value, which is why the idea appears in probability as well as in everyday arithmetic.
Recap
- A weighted average is : products added on top, weights added below.
- Equal weights give the ordinary mean, and a zero weight removes its value.
- Normalising the weights to shares that add to 1 gives the same answer and is the form used in expected value.
- Use it whenever the values should not count equally, such as grades by credits, prices by quantity, or recent observations in an exponential moving average.
- Read next: Mean and Variance builds on the mean and adds the spread, and Expected Value is the weighted average where the weights are probabilities.
Check yourself
QuestionValues 10 and 30 have weights 2 and 3. What is the weighted average?Show answer
The products are and . The sum of products is 110, and the sum of weights is 5. The weighted average is . Check: 22 lies between 10 and 30 and is closer to 30, where the larger weight is.
QuestionA student has grades of 3.0 in a 4-credit course and 4.0 in a 2-credit course. What is their GPA, and why is it not the simple average of 3.5?Show answer
The products are and . The sum is 20, and the total credits are 6, so the GPA is . The simple average of 3.5 gives the 2-credit course the same influence as the 4-credit course. The weighted version lets the larger course count twice as much, so the answer is closer to 3.0.
QuestionTwo classes have average test scores of 70 with 10 students and 90 with 30 students. A teacher reports the overall average as 80. Is this right? Explain with the formula.Show answer
No. The overall average must weight each class by its size: . Averaging the two class averages gives 80, which treats the 30-student class as if it had only 10 students.
QuestionA shop sells some apples at 2 dollars each and some at 4 dollars each, and the total revenue is 60 dollars from 20 apples. What is the average price per apple, and what fact does this tell you about the sales mix?Show answer
The average price is dollars. That is exactly halfway between 2 and 4, so the two groups of apples must be equal in number: 10 sold at 2 dollars and 10 at 4 dollars give dollars. With equal numbers the weighted and ordinary averages coincide, which is the special case described in the math section.
Sources
- Wikipedia: Weighted arithmetic mean.
- Wikipedia: Grade point average, for the course-credit example.