This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Abbreviated way to create groups of (nearly) identical values. | |
import numpy as np | |
# Random example data. | |
a = np.array([11.1, 1, 1, 2, 3, 4, 5, 5, 1, 5, 5, 6, 6, 7, 9, 7, 8, 7, 10, 11.1, 11.2]) | |
EPS = 1e-7 # matching precision | |
asorted = np.sort(a) # line up the values neatly, but don't alter | |
# Get all indices where a change in value occurs | |
indices = np.where(np.abs(np.diff(asorted)) > EPS)[0] + 1 | |
# Group identical values |
NewerOlder