0

I have read two bands from a remote sensed image and I want to subtract them. If the difference is greater than a threshold, I want the output to be 1, otherwise 0. Yet, this error keeps popping up The truth value of an array with more than one element is ambiguous. Use a.any() or a.all(). Below the lines of code are illustrated.

red_array = red.ReadAsArray()
swir1_array = swir1.ReadAsArray()
# Substracting the bands creating a raster that enhances ships ready for classification
# red_swir = np.where(((red_array > 2000) & (swir1_array > 900)), 0, red_array - swir1_array).astype(np.int16)
difference = (red_array - swir1_array).astype(np.int16)
red_swir = np.where((difference > 2000, 1, 0))

Any help here?

Karantai
  • 73
  • 8
  • 1
    Welcome back to Stack Overflow. As a refresher, please read [ask] and https://meta.stackoverflow.com/questions/284236 and https://meta.stackoverflow.com/questions/261592. Even the easiest, most obvious possible searches for this question would directly point you at existing answers, because this question is asked constantly. – Karl Knechtel Nov 16 '21 at 09:49
  • Show traceback. I'd also test `difference > 2000` by itself. I don't the `where` itself is raising the error. – hpaulj Nov 16 '21 at 15:54

0 Answers0