1

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.

Matt
  • 11
  • 1
    What do you mean by "divide Matrix 1 ($M_1$) by Matrix 2 ($M_2$)"? There's no standard definition of what it means to divide one arbitrary matrix by another (even if they're of the same size). My guess is that you mean elementwise division of each entry of $\ M_1\ $ by the corresponding entry of $\ M_2\ $. Is that correct? However, that would require all of the entries of $\ M_2\ $ to be non-zero. Is that the case? If not, what do you do with those entries which are zero? – lonza leggiera Nov 24 '22 at 05:20
  • Hello Ionza, thank you for your response. As you correctly assumed, I am performing element-wise division of the arrays. There are no zero entries in the matrix, but rather, there are NaN entries which indicate an absence of data (i.e. a value cannot be computed for that element). I have made these changes in the above post. – Matt Nov 24 '22 at 15:23
  • Thank you Mariano, simplifying the problem as you suggested makes things very clear. In terms of order of operations, I am assuming it is dependant on what I am trying to do? – Matt Nov 24 '22 at 16:17

0 Answers0