total of non zero value

1k Views Asked by At

I want to write a math formula that represents the average of non zero value e.g. if I have 4 numbers, one of them is zero, then the sum of the numbers will be divided by 3. Is it correct to say:

$$ \frac {\sum_{k=1}^{4} x_{k}} {|x_{k} > 0|} $$

1

There are 1 best solutions below

4
On

I think what you want is the following:

$$\frac{\sum_{k=1}^{4} x_{k}}{\sum_{k:x_{k} \neq 0} 1}.$$

You could alternatively define a set $S$ such that

$$S = \{k: x_{k} \neq 0\}$$

and then sum over this set so that you would have

$$\frac{\sum_{k=1}^{4} x_{k}}{\sum_{S} 1}.$$

Note that adding zeros to the sum will not change the numerator. However, you need to have at least one non-zero value $x_{k}$ for this to make any sense.