3

The !True returns False but how can I negate a boolean vector such as {True, False, True}? The exclamanation mark does not work here like this !{True,False,True}.

hhh
  • 2,603
  • 2
  • 19
  • 30
  • 3
    doing ??Not shows Not is not Listable. If a function foo is Listable, then one can write foo[{....}], and then foo will automatically by applied to each element in the list. For example, if you do ??Sin you'll see it says it is Listable. For non-listable functions, you can use Map, as in Map[Not,{True,False,True}] or Not[#] & /@ v etc... So, the first thing to always check is to do ?? in order to see if a function is Listable or not. – Nasser Nov 09 '13 at 17:15
  • @Nasser: Not[#] & can be written more concisely as Not. –  Nov 09 '13 at 18:26

2 Answers2

8

Thread:

Thread[!{True, False, True}]
(* {False, True, False} *)
ssch
  • 16,590
  • 2
  • 53
  • 88
7

One straightforward way to negate vectors is to use the full form of !, which it Not

q = {True, True, False};
Not /@ q
{False, False, True}

or equivalently Map[Not, q].

bill s
  • 68,936
  • 4
  • 101
  • 191