# Suppose $M$ is an $m \times n$ matrix such that all rows and columns of $M$ sum to $1$. Show that $m=n$

I find this a rather awkward question, and I was given a hint: use invariants, which I found even more awkward.

Suppose $M$ is an $m \times n$ matrix such that all rows and columns of $M$ sum to $1$. Show that $m=n$.

I have no clue how this is a problem on invariants, let alone how to solve this problem. I'll need hints on why this is the case.

If $M$ has $m$ rows that sum to $1$, the sum of the matrix is $m$.

If $M$ has $n$ columns that sum to $1$, the sum of the matrix is $n$.

The sum of the matrix is invariant, therefore $m=n$.

Hint: What is the sum of all numbers in the matrix?

Let $\mathrm A \in \mathbb R^{m \times n}$ have its $m$ rows and $n$ columns sum to $1$. Hence,

$$\underbrace{1_m^T \mathrm A}_{=1_n^T} 1_n = 1_n^T 1_n = n$$

and

$$1_m^T \underbrace{\mathrm A 1_n}_{=1_m} = 1_m^T 1_m = m$$

Thus, $m = n$.