I have a numpy array:
>>> n1 = np.array([[1, 4], [1, 5], [2, 4], [7, 2], [1, 3], [4, 7], [2, 9]])
>>> n1
array([[1, 4],
[1, 5],
[2, 4],
[7, 2],
[1, 3],
[4, 7],
[2, 9]])
I'm looking for a way to find the index of the occurrence of a value in the first column that follows the occurrence of a value greater than it. In this instance, I want:
array([4, 6])
because the value 1 is less than 7, and the value 2 is less than 4 (all in column 0)
Is there a nice Pythonic way of doing this?
n1[1:,:]-n1[:-1,:], the difference between successive rows.n2that contains only column 0 ofn1, and using your suggestion, I builtnp.where(n2[1:]-n2[:-1] < 0)which gives me(array([3, 5]),), notarray([4, 6])wheregives a tuple, one element per dimension of the condition. Your case is 1d, so the result is a 1 element tuple.