For one-dimensional arrays you could use np.where to get the indices of the array and apply those in the conditional indexing.
array = np.random.randn(5)
>>> [-0.65572047 0.39725663 -0.2727869 -1.62292975 0.12211058]
# Use np.where to return indices
np.where(array)[0]
>>> [0 1 2 3 4]
# Condition can include indices like this:
array[(array * np.where(array)[0]) > threshold] = np.nan
You can extend this solution to two-dimensional arrays, however you need to determine how you want to define a two-dimensional index in your condition.
Here are the two indices (one for each dimension) you could plug into the conditional indexing:
array = np.random.rand(5, 5)
indices = np.where(array)[0].reshape((5, 5))
print(indices)
>>> [[0 0 0 0 0]
[1 1 1 1 1]
[2 2 2 2 2]
[3 3 3 3 3]
[4 4 4 4 4]]
indices = np.where(array)[1].reshape((5, 5))
print(indices)
>>> [[0 1 2 3 4]
[0 1 2 3 4]
[0 1 2 3 4]
[0 1 2 3 4]
[0 1 2 3 4]]
arr[ arr[i] * scale[i] > threshold] = np.nanarr[ arr * scale > threshold] = np.nan? It depends a bit on the shape of thescalearray