How To Find Larger Numbers Of Any Selected Number In A Series In An Ascending Order In Numpy?
I have a series of randomly scrabbled numbers. I want to pick a number (say X), and then find and write larger numbers than X in an ascending order. I’m using Python and NumPy. E
Solution 1:
You can use np.maximum.accumulate
like so::
a = np.array([4, 8, 5, 9, 3, 11, 17, 19, 9, 15, 16])
X = 4
withreps = np.maximum.accumulate(a[np.argmax(a==X):])
result = withreps[np.where(np.diff(withreps, prepend=withreps[0]-1))]
result
# array([ 4, 8, 9, 11, 17, 19])
Post a Comment for "How To Find Larger Numbers Of Any Selected Number In A Series In An Ascending Order In Numpy?"