For instance:
a = RandomReal[{0, 10}, {4, 4}];
b = RandomReal[{0, 10}, {4, 4}];
MapThread[Equal, {a, b}, 2] // Flatten
(*
{False, False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False}
*)
The above equates the matrices element by element. To see this, define
c = Array[Subscript[d, #1, #2] &, {4, 4}]
then try the code I gave, ie, MapThread[Equal, {c, b}, 2]
and your code, Thread /@ Thread[c == b] // Flatten
; they give the same answer. But yours does not work for numeric matrices: Thread /@ Thread[a \[Equal] b] // Flatten
errors. To see why, trace what is happening: Thread /@ Thread[a == b] // Trace
and you see it first evaluates a==b
, then threads. So, if one of the matrices is symbolic, this works OK as the Equal
returns unevaluated, then gets threaded; but if both are numeric, the Equal[a,b]
evaluates to False
, and then there's nothing to thread or flatten.
Thus, your code and Rojo's answer rely on one of the matrices being symbolic so that the Equal[a,b]
part remains unevaluated. They don't equate a
and b
elementwise if they are numeric (not that this matters for what you want to do; I just thought it was worth mentioning).