Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import statistics
- def getExtremes(array, withIndex=False):
- """
- Return all extremes in an array.
- An "extreme" is any value in a group that exceeds the standard deviation in the positive or negative of the mean.
- withIndex returns all extremes in a tuple with their index in the array fomatted (<value>, <index>)
- """
- arrayMean = statistics.mean(array)
- stdDev = statistics.pstdev(array)
- final = []
- for item in (array if not withIndex else [(value, index) for index, value in enumerate(array)]):
- item, fitem = item[0] if withIndex else item, item
- if (item < arrayMean - stdDev) or (item > arrayMean + stdDev):
- final.append(fitem)
- return final
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement