# Map Algebra syntax

I'm trying to create a new raster from an existing slope raster where slopes are between 5 and 20 degrees. However, I'm receiving the error "ValueError: The truth value of a raster is ambiguous. Invalid use of raster with Boolean operator or function. Check the use of parentheses where applicable."

It's obvious it just has to do with my Map Algebra syntax, but I can't figure it out. Here's a snippet of my code:

``````slope - Slope("elevation")    # creates slope raster, elevation is raster object
goodslope = (slope < 20) & (slope > 5)
goodslope.save("Final")
``````

Maybe I have to use a Con() statement?

• Please add tag(s) for the software and version. – Tom Apr 4 '16 at 4:03
• Please say in the body of your question precisely the software that you are using. If you tag it correctly that will help a potential answerer find your question too. – PolyGeo Apr 4 '16 at 4:07
• Please provide a minimal complete example that will reproduce the problem. I don't think that snippet is your actual code, otherwise you'd get a `NameError: name 'slope' is not defined` as the slope variable is not getting defined in the `slope - Slope("elevation")` line (notice the `-` symbol instead of the `=` symbol). – user2856 Apr 4 '16 at 4:23
• Are you sure you are using parentheses...? Can you run that exact snippet (with 1st line fixed to define `slope` correctly)? Your code works fine for me in 10.2.2. I get the ValueError: The truth value of a raster is ambiguous... exception if I don't have parentheses around the `(slope < 20)` and `(slope > 5)` relational expressions, i.e. `goodslope = slope < 20 & slope > 5`. This is because Boolean (~, &, ^, |) operators have a higher precedence level than Relational (<, <=, >, >=, ==, !=) operators. – user2856 Apr 4 '16 at 4:26

``````slope = Slope("elevation") # elevation is the name of a raster!