I have two matrices A and B of identical dimensions. What's the simplest (shortest) way to find the indices of differing elements?

  • $\begingroup$ related: 43938 $\endgroup$
    – Kuba
    Commented May 8, 2014 at 17:49

1 Answer 1


I've failed to find a duplicate so:

SparseArray[A - B]["NonzeroPositions"]

Position[A - B, x_ /; x != 0., {2}]

I hope those are numeric matrices, if not then you have to watch out on the Condition in the second solution.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.