Numpy get index of arange in 2d array

Try this

np.nonzero(arr == np.arange(arr.shape[0])[:,None])[1]

Out[15]: array([0, 1, 1, 2], dtype=int64)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top