diff --git a/src/Numerics/Statistics/ArrayStatistics.cs b/src/Numerics/Statistics/ArrayStatistics.cs index 63646059..2877f0c3 100644 --- a/src/Numerics/Statistics/ArrayStatistics.cs +++ b/src/Numerics/Statistics/ArrayStatistics.cs @@ -65,6 +65,26 @@ namespace MathNet.Numerics.Statistics return min; } + /// + /// Returns the smallest value from the unsorted data array. + /// Returns NaN if data is empty or any entry is NaN. + /// + /// Sample array, no sorting is assumed. + public static float Minimum(float[] data) + { + if (data.Length == 0) return float.NaN; + + var min = float.PositiveInfinity; + for (int i = 0; i < data.Length; i++) + { + if (data[i] < min || float.IsNaN(data[i])) + { + min = data[i]; + } + } + return min; + } + /// /// Returns the smallest value from the unsorted data array. /// Returns NaN if data is empty or any entry is NaN. @@ -85,6 +105,26 @@ namespace MathNet.Numerics.Statistics return max; } + /// + /// Returns the smallest value from the unsorted data array. + /// Returns NaN if data is empty or any entry is NaN. + /// + /// Sample array, no sorting is assumed. + public static float Maximum(float[] data) + { + if (data.Length == 0) return float.NaN; + + var max = float.NegativeInfinity; + for (int i = 0; i < data.Length; i++) + { + if (data[i] > max || float.IsNaN(data[i])) + { + max = data[i]; + } + } + return max; + } + /// /// Estimates the arithmetic sample mean from the unsorted data array. /// Returns NaN if data is empty or any entry is NaN.