# How to check if all the entries in columns of a matrix are equal?

Assume we have the following matrix/tensor. How can I test if the column has the same element? 4-6 and 8-9 columns has the same element.

$\left( \begin{array}{cccccccccc} \{2,3\} & \{2,3\} & \{2,4\} & \{2,4\} & \{2,4\} & \{2,4\} & \{2,3\} & \{2,3\} & \{2,3\} & \{2,3\} \\ \{2,3\} & \{2,4\} & \{2,4\} & \{2,4\} & \{2,4\} & \{2,4\} & \{2,3\} & \{2,3\} & \{2,3\} & \{1,3\} \\ \{1,3\} & \{2,4\} & \{1,3\} & \{2,4\} & \{2,4\} & \{2,4\} & \{2,3\} & \{2,3\} & \{2,3\} & \{2,3\} \\ \{2,3\} & \{2,4\} & \{1,3\} & \{2,4\} & \{2,4\} & \{2,4\} & \{1,3\} & \{2,3\} & \{2,3\} & \{2,3\} \\ \end{array}\right)$

mat={{{2, 3}, {2, 3}, {2, 4}, {2, 4}, {2, 4}, {2, 4}, {2, 3}, {2, 3}, {2,
3}, {2, 3}}, {{2, 3}, {2, 4}, {2, 4}, {2, 4}, {2, 4}, {2, 4}, {2,
3}, {2, 3}, {2, 3}, {1, 3}}, {{1, 3}, {2, 4}, {1, 3}, {2, 4}, {2,
4}, {2, 4}, {2, 3}, {2, 3}, {2, 3}, {2, 3}}, {{2, 3}, {2, 4}, {1,
3}, {2, 4}, {2, 4}, {2, 4}, {1, 3}, {2, 3}, {2, 3}, {2, 3}}};


I have tried this but it didn't work.

AllTrue[mat[[All, #]], SameQ] & /@ Range@10

• SameQ @@@ Transpose[mat]? – J. M. is away Mar 31 '18 at 5:53
• Yes, that works perfectly. Thanks. – Okkes Dulgerci Mar 31 '18 at 6:19
• For larger matrices, integer arithmetic (performed in the reals) might be more performant: {True, False}[[ Unitize[ (ConstantArray[1., Dimensions[A][[1]] - 1].Abs[ Differences[A]]).ConstantArray[1., Dimensions[A][[3]]] ] + 1]]. – Henrik Schumacher Mar 31 '18 at 8:55
• My matrix is at most 10x90 – Okkes Dulgerci Mar 31 '18 at 15:02
• Then it's probably not worth the effort. – Henrik Schumacher Mar 31 '18 at 20:20