The input array is treated as histogram, i.e. its indexes are treated as values of stochastic function, but array values are treated as "probabilities" (total amount of hits).
public static double HistogramMean(this int[] values) { double total = 0; double mean = 0; for (int i = 0; i < values.Length; i++) { int hits = values[i]; mean += (double)i * hits; total += hits; } return (total == 0) ? 0 : mean / total; }