Weighted Average for a-b & ((a-b)/a)

82 views Asked by At

How do you calculate weighted average for: S, where S = a-b ?

I understand that if a and b have the same weights, i would compute S = a-b and then use the weights to compute weighted average of S.

But here I have the weight vectors for vector a and vector b. What weights do I use for S?

On the same note, what if S = ((a-b)/a) ?

1

There are 1 answers

2
Matias Lopez On

First you need to define a weights vector that haves the same dimentions of S.

For example:

a = np.array([1, 2, 3, 4])
b = np.array([6, 7, 4, 10])
S = a - b

Then define a weight vector with the same lenth of S and compute the weighted average:

weights = np.array([2, 1, 6, 5])
avg = sum(S * weights) / sum(weights)
# avg = -3.642857

This weights vector depends on the problem you are trying to solve. For example it can be the substraction of a and b weights, their sum, etc.

For S = (a - b) / a repeat the previous steps.