Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
    
related: 43938 –  Kuba May 8 at 17:49
add comment

1 Answer 1

up vote 6 down vote accepted

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 second solution.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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