- (Negate) operator

Available with Spatial Analyst license.

Available with Image Analyst license.

Summary

Changes the sign of the cell values (multiplies by -1) of the input raster on a cell-by-cell basis.

Illustration

Negate illustration
OutRas = -Raster("InRas1")

Discussion

When using an operator with a raster input, the result will be a raster. However, if all inputs are numbers, the result is a number.

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, see the operator precedence table in Working with operators in Map Algebra. You can use parentheses to control the execution order.

If the input is integer, the output will be integer. If the input is floating point, the output will be floating point.

If the input is a multiband raster, the output will be a multiband raster. The operator will perform the operation on each band in the input.

If the input is a multidimensional raster, all slices from all variables will be processed, and the output will be a multidimensional raster.

Parameters

OperandExplanationData Type
in_raster_or_constant

The input raster to be negated (multiplied by -1).

Raster Layer | Constant

Code sample

Unary - (Negate) example 1 (Python window)

This sample changes the sign of the values in the input raster.

import arcpy
from arcpy import env
from arcpy.ia import *
env.workspace = "C:/iapyexamples/data"
outNegate = - Raster("degs")
outNegate.save("C:/iapyexamples/output/outneg")
Unary - (Negate) example 2 (stand-alone script)

This sample changes the sign of the values in the input raster.

# Name: Op_Negate_Ex_02.py
# Description: Changes the sign (multiplies by -1) of the cell values
#              of the input raster on a cell-by-cell basis 
# Requirements: Image Analyst Extension

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

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

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

# Execute Negate
outNegate = -(inRaster)

# Save the output 
outNegate.save("C:/iapyexamples/output/outnegate")

Related topics