Check Whether Numpy Array Row Is Smaller Than The Next
Suppose i have the following array: In [1]: k Out[1]: array([[0], [1], [2], [7], [4], [5], [6]]) I would like to check whether each row
Solution 1:
You can also use np.diff
along axis 0 and check whether the result is greater than 0.
arr = np.array([[0],
[1],
[2],
[7],
[4],
[5],
[6]])
np.diff(arr, axis=0) > 0
array([[ True], 1 > 0
[ True], 2 > 1
[ True], 7 > 2
[False], 4 > 7
[ True], 5 > 4
[ True]]) 6 > 5
There is no row follow [6]
and thus the result is one row shorter.
Post a Comment for "Check Whether Numpy Array Row Is Smaller Than The Next"