The three logical operators, &, | and ~, are supported for both scalar and matrices.
This operator performs the logical AND operation on the operands. It returns 1 if both are non-zero; otherwise it returns zero. For matrices, the operation is performed on individual elements.
A = [1,2]; B = [1,0]
print(A & B)
> [Matrix] 1 x 2
1 0
Note | This operator is different than the && operator, which is explained in the section Logical Keywords. |
This operator performs the logical OR operation on the operands. It returns 1 if either is non-zero; otherwise it returns zero. For matrices, the operation is performed on individual elements.
A = [2,0]; B = [0,0]
print(A | B)
> [Matrix] 1 x 2
1 0
Note | This operator is different than the || operator, which is explained in the section Logical Keywords. |
This unary operator performs the logical NOT operation on the operand. It returns 0 if the operand is non-zero; otherwise it returns 1. For matrices, the operation is performed on individual elements.
A = [2,0];
print(~A)
> [Matrix] 1 x 2
0 1