I have a numpy array - image with various values: example image = [1 ,2 ,2, 3, 4, 4, 4, 4, 5, 6, 6 ,7 ,8 ,8 ,8 ,8] I want to replace only those numbers occurring less than twice - by a specific number, let's say 0. I managed to create the list of those numbers like this:
(unique, counts) = np.unique(image, return_counts=True)
frequencies = np.asarray((unique, counts)).T
freq = frequencies[frequencies[:,1] < 2,0]
print(freq)
array([1, 3, 5, 7], dtype=int64)
How do I replace those numbers by zero?
the outcome should look like : [0 ,2 ,2, 0, 4, 4, 4, 4, 0, 6, 6 ,0 ,8 ,8 ,8 ,8]
Thanks in advance!