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.

This is a special case of my question How to do nor on matrices?

     a = IdentityMatrix[3]; 
     b = {{1, 0}, {0, 1}, {0, 0}} 
     MapThread[Complement[#1, #2] &, {a, b}] 

Mathematica returns {{}, {}, {1}} , whereas I expect {{0}, {0}, {1}}, which is what I need.

share|improve this question
    
{{}, {}, {1}} is what I would expect. Just replace Complement with e.g. c in MapThread and observe what are the direct arguments to Complement. –  István Zachar Feb 17 '13 at 14:56
1  
possible duplicate of How to do nor on matrices? –  István Zachar Feb 17 '13 at 14:58
    
Yes, this is a special case of another question of mine. But that method does not work for identity matrix. –  novice Feb 17 '13 at 15:00
    
@IstvánZachar The OP expects to get using Complement[ConstantArray[0, 10], {0}] a list of 9 zeros! So Complement based solution does not work for him as opposed to his previous question that you have noted as duplicate. –  PlatoManiac Feb 17 '13 at 15:04
3  
Please edit title so it doesn't ask for "nor": "nor" suggest the logical/bitwise operation, which may be implemented by: bitNor[{x_,y_}]:=Mod[BitNot[BitOr[x,y]],2]. –  murray Feb 17 '13 at 17:00

2 Answers 2

up vote 2 down vote accepted

Try the following hack but remember this is a solution specific to your question no general solution!

newComplement[listA_, listB_] := Block[{check},
  check[list_, var_] := Module[{pos},
     pos = Position[list, var];
     If[Length@pos != 0, Drop[list, First@pos], list]
    ];
  If[(MemberQ[listA, #] & /@ listB) /. List ->  And,Fold[check, listA, listB], listA]
];

Testing it!

MapThread[newComplement[#1, #2] &, {a, b}]

{{0}, {0}, {1}}

share|improve this answer
    
I have tested the new self-defined newComplement.It works for n-order identity matrix with the complement of any columns. Much Gratitude! –  novice Feb 17 '13 at 15:55
    
Plato, you don't need the Function in MapThread. You can use newComplement directly. I just made that change to an older answer of yours as well. –  Mr.Wizard Mar 31 '13 at 0:12

Does this do what you want?

a = IdentityMatrix[3];

b = {{1, 0}, {0, 1}, {0, 0}};

MapThread[Complement, {a, b}] /. {} -> {0}
{{0}, {0}, {1}}
share|improve this answer

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.