Why the mean of a quotient is not equivalent to a quotient of means?

100 Views Asked by At

I have a problem where I am deciding upon the correct order of operations. I have two 2-dimensional matrices that I wish to divide in an element-wise fashion. Both matrices have dimensions $256 \times 256$. Say that I wish to divide Matrix 1 ($M_1$) by Matrix 2 ($M_2$) to get my desired matrix, $M_3$.

$$ M_3 = \frac{M_1}{M_2} $$

It should be noted that there are no elements with zero in either matrix. There are elements without data, and as such, are flagged with NaN. Thereby, if an element has a NaN entry in one matrix, it will also be NaN in that exact same element in the other matrix. So, for example, if position 52,52 in matrix 1 is NaN then $M_{1(52,52)}=NaN$ $M_{2(52,52)}$ is also NaN. For my first attempt at deriving the mean value of $M_3$ (method 1), I simply take the mean of the all the entires comprising the $256 \times 256$ matrix. This gives me a mean of $\overline{M}_3$.

For my second attempt (method 2) at deriving the mean value of $M_3$, I took the mean of $M_1$ and $M_2$ separately and then divided the computed means:

$$ \overline{M}_3 = \frac{mean(M_1)}{mean(M_2)}$$

However, when I compared $\overline{M_3}$ as computed via methods 1 and 2, I found that they were not the same. I found a discussion that outlined how these two operations are not equivalent. I have thereby concluded that:

$$ mean(M_3) \neq \frac{mean \left( M_1\right)}{ mean\left( M_2\right)} $$

However, I am wondering why this is the case? And, more importantly, if there is a 'correct' order of operations? Or is the order dependent on what I am trying to do?

Note: This is my first post on this site, so if there are issues with my formatting, or I need to divulge additional information, please let me know and I will be happy to oblige.