2 years ago
#41317
Reut
Unexcpected behavior in numpy when changing values by conditions
I have numpy array with the shape (104,107) and values between 0- 0.6 :
I want to classify the image by three classes:
- Pixels with value larger than 0.25 (high_bord) ->get value 1
- Pixels with value smaller than 0.17 (low_bord) ->get value 2
- Pixels with value between low_bord and high_bord -> get value 3
This is the script I have used for the classification:
arr[arr < low_bord] = 1
arr[arr > high_bord] = 2
arr[(arr>=low_bord)&(arr<=high_bord)] = 3
that gives me the following results:
as it can be seen, the minimum value in this case is 2, which could ne interperated as- only 2 conditions were found. However, I believe this results ar wrong, and when I change the value of the first condition to be -1 , then I get three classes:
arr[arr < low_bord] = -1
arr[arr > high_bord] = 2
arr[(arr>=low_bord)&(arr<=high_bord)] = 3
I have the suspicion that it has t odo with the order to the conditions (e.g ,after the first condition, the low pixels have values that are larger than the high bord and get value 2? ).
My end goal is to be able to give each class unique correct value (and then to color it accordingly)
python
numpy
conditional-statements
mask
0 Answers
Your Answer