The Harmonic Mean function in Python (scipy.stats.hmean
) requires that the input be positive numbers.
For example:
from scipy import st
the mathematical definition of harmonic mean itself does not forbid applications to negative numbers (although you may not want to calculate the harmonic mean of +1 and -1), however, it is designed to calculate the mean for quantities like ratios so that it would give equal weight to each data point, while in arithmetic means or such the ratio of extreme data points would acquire much high weight and is thus undesired.
So you either could try to hardcode the definition by yourself like @HYRY suggested, or may have applied the harmonic mean in the wrong context.