4>3 gives True.
What is the "greater_operator" to obtain the result 4?
For lists accordingly:
{{1, 2}, {3, 4}} "greater_operator" {{5, 1}, {7, 2}}
should give a resulting list: {{5, 2}, {7, 4}}
Answer
One way to get the desired behavior is to make the Max function Listable:
Unprotect[Max];
SetAttributes[Max, Listable];
lst1 = {{1, 2}, {3, 4}}; lst2 = {{5, 1}, {7, 2}};
Max[lst1, lst2]
{{5, 2}, {7, 4}}
You could also do the same thing a bit more safely by changing the Max function attributes only when needed. For instance:
max[list1_, list2_] := Module[{out}, Unprotect[Max]; SetAttributes[Max, Listable];
out = Max[list1, list2]; ClearAttributes[Max, Listable]; out]
Comments
Post a Comment