I have an array that looks something like this:
np.array([[0 , 5, 1], [0, 0, 3], [1, 7, 0]])
I want to check that each element is nonzero, and if it is nonzero replace it with a number that tracks how many elements it has checked. That is, I want the final product to look like
np.array([[0, 2, 3], [0, 0, 6], [7, 8, 0]])
where the first row reads [0, 2, 3] because the second element was checked second, passed the test, and then replaced (and so on). Can anyone think of any solutions? I imagine that numpy's indexing will be quite useful here. Thanks!