/// <summary> /// Calculate the harmonic mean value of array data. Supported data type: double/float/int. /// </summary> /// <param name="data">The array data to calculate statistic value.</param> /// <typeparam name="TDataType">Supported data type: double/float/int.</typeparam> /// <returns>The harmonic mean value of array data.</returns> /// <exception cref="NotSupportedException">Supported data type: double/float/int.</exception> public static double HarmonicMean <TDataType>(TDataType[] data) { double harmonicMean = double.NaN; if (ReferenceEquals(typeof(TDataType), typeof(double))) { double[] doubleData = data as double[]; harmonicMean = ArrayStatistics.HarmonicMean(doubleData); } else if (ReferenceEquals(typeof(TDataType), typeof(float))) { float[] floatData = data as float[]; harmonicMean = ArrayStatistics.HarmonicMean(floatData); } else if (ReferenceEquals(typeof(TDataType), typeof(int))) { int[] intData = data as int[]; harmonicMean = ArrayStatistics.HarmonicMean(intData); } else { throw new NotSupportedException("Unsupported data type."); } return(harmonicMean); }