TITLE: How to compute the average in modular arithmetic?
QUESTION [6 upvotes]: Let's say I'm working in modulo 10 and I have some numbers: 0,0,1,1,9.
How can I calculate the average?
I'm expecting 0,2 in my example (0+0+1+1-1 over 5).

REPLY [3 votes]: We can attempt to define your intuitive "modular average" in the following way.
Let our set of data points be $\{a_1,a_2,\dots,a_n\}$
We define a modular average of the data points to be a point $\bar{a}$ such that $\sum\limits_{i=1}^n d(a_i,\bar{a})$ is minimized where the summation here is not done using modular arithmetic, but rather normal arithmetic and $d$ here is a distance function where $d(a,b) = \min\limits_{x\in[a],~y\in[b]}(|x-y|)$ where $[a]$ is the equivalence class of $a$.
We have as an example then, the "modular average" of $\{1,9\}$ in base 10 to be $0$ since this minimizes the sum, giving a sum of $2$ since $d(1,0)+d(9,0)=1+1=2$.  On the other hand, $4$ would not be since you would have $d(1,4)+d(9,4)=3+5=8$.
This is not perfect however as in this play example we would also have every other value "between" $9$ and $1$ also minimizing the sum, for example, $1$ also minimizes the sum as $d(1,1)+d(9,1)=0+2=2$ as well.  This does have the benefit however that an actual average will be a modular average.
To account for this, perhaps we might want to look instead at the values of $\bar{a}$ such that instead $\sum\limits_{i=1}^nd(a_i,\bar{a})^2$ is minimized.  In doing so, perhaps we reduce the number of available modular averages, but we lose the property that our usual average will agree with the modular average under several circumstances.