Message Boards Message Boards

0
|
7033 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Perform element-wise matrix operations (EqualTo)?

POSTED BY: Rebecca A
4 Replies
In[1]:= Thread[Flatten[amat] == Flatten[bmat]]

Out[1]= {a11 == b11, a12 == b12, a21 == b21, a22 == b22, a31 == b31, 
 a32 == b32, a41 == b41, a42 == b42}
In[4]:= Flatten[Thread /@ Thread[amat == bmat]]

Out[4]= {a11 == b11, a12 == b12, a21 == b21, a22 == b22, a31 == b31, 
 a32 == b32, a41 == b41, a42 == b42}
POSTED BY: Frank Kampas
POSTED BY: Sander Huisman
Posted 8 years ago

You already have a direct and simple solution( flatten first) using basic Mathematica and it works for any depth of nesting. A different way to do that is to use a Listable function (alias for "==") and flatten the result.

eq[x_, y_] = Equal[x, y]; SetAttributes[eq, Listable];
Flatten[eq[amat, bmat]]

{a11 == b11, a12 == b12, a21 == b21, a22 == b22, a31 == b31, 
 a32 == b32, a41 == b41, a42 == b42}
POSTED BY: Douglas Kubler
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract