I want to replace a numpy array values with a counter, if they meet a condition.
'Arr' is a NxM numpy array. I would like 'ArrCount' (NxM) to have values from i=1 to i=n, if the value in 'Arr' doesn't equal 65535.
for large arrays, iterating over each cell takes a long time.
import numpy as np
ArrCount= np.empty_like(Arr)
i = 1
for index, x in np.ndenumerate(Arr):
if x!= 65535:
ArrCount[index] = i
i += 1
I've also tries working with mask and Boolean arrays, but this doesn't improve the iterating time. Is there a better way of doing this?