+ 1
i need function Finding mode for sequencing.
i need function which Finding mode for sequencing and If you have two or more modes of mode. Return all And if you do not have it, None. thanks advanced
1 Respuesta
+ 1
The typical answer would be to use standard implementations for mode() such as in Numpy. However, the non-standard handling you have requested (mainly multiples) can be accomplished without external imports.
def mode(array):
if not array:
return None
items = set(array)
most = max(map(array.count, items))
if most < 2:
return None
modes = list(filter(lambda x: array.count(x) == most, items))
return modes[0] if len(modes) == 1 else modes