>>> import numpy as np >>> a = np.asarray([[1,2,3],[1,5,7],[4,3,6]])
Find the difference between each item. np.diff has an argument that allows you to specify the axis to perform diff
>>> np.diff(a) array([[ 1, 1], [ 4, 2], [-1, 3]])
Check if each difference is greater than 0.
>>> np.diff(a) > 0 array([[ True, True], [ True, True], [False, True]], dtype=bool)
Make sure all differences are> 0
>>> np.all(np.diff(a) > 0) False >>>
As suggested by @Jaime - check that each element is larger than the element to its left:
np.all(a[:, 1:] >= a[:, :-1], axis=1)
which seems to be about twice as fast / more efficient than my solution.
wwii
source share