Skip To Content


Available with Spatial Analyst license.

Available with Image Analyst license.


Performs a Boolean-complement (Not) operation on the cell values of the input raster.


Boolean Not illustration
OutRas = ~ Raster("InRas1")


The ~ operator will perform a Boolean Not operation when the input (operand) is a raster. If the input (operand) is a number, then the ~ operator will perform a Bitwise Not operation. For more information on how to work with operators, refer to Working with operators.

When multiple operators are used in an expression, they are not necessarily executed in left-to-right order. The operator with the highest precedence value will be executed first. For more information on operator precedence, see operator precedence table. You can use parentheses to control the execution order.

Boolean (~, &, ^, |) operators have a higher precedence level than Relational (<, <=, >, >=, ==, !=) operators. Therefore, when Boolean operators are used in the same expression as Relational operators, the Boolean operators will be executed first. To change the order of execution, use parentheses.

When multiple Relational and/or Boolean operators are used consecutively in a single expression, in some cases it may fail to execute. To avoid this potential problem, use appropriate parentheses in the expression so that the execution order of the operators is explicitly defined. For more information, see Complex Statement Rules.

Only a single input is necessary for the Boolean evaluation to take place.

If the input values are floating point, they are converted to integer values by truncation before the Boolean operation is performed. The output values are always integer.


~ in_raster_or_constant
OperandExplanationData Type

The input to use in the Boolean Not operation.

Raster Layer | Constant

Return Value

NameExplanationData Type

The output raster object.

The output values will be either 0 or 1.


Code sample

~ (Boolean Not) example 1 (Python window)

This sample performs a Boolean Not (complement) operation on an input raster.

import arcpy
from arcpy import env
from import *
env.workspace = "C:/sapyexamples/data"
outBooleanNot = ~ Raster("degs")"C:/sapyexamples/output/outboolnot.tif")
~ (Boolean Not) example 2 (stand-alone script)

This sample performs a Boolean Not (complement) operation on an input raster.

# Name:
# Description: Performs a Boolean complement (NOT) operation on the
#              cell values of an input raster
# Requirements: Spatial Analyst Extension

# Import system modules
import arcpy
from arcpy import env
from import *

# Set environment settings
env.workspace = "C:/sapyexamples/data"

# Set local variables
inRaster = Raster("degs")

# Execute BooleanNot
outBooleanNot = ~ inRaster

# Save the output"C:/sapyexamples/output/outboolnot")

Related topics