Java mean mean(double[] samples)

Here you can find the source of mean(double[] samples)

Description

mean

License

Open Source License

Declaration

public static double mean(double[] samples) throws Exception 

Method Source Code

//package com.java2s;

public class Main {
    public static double mean(double[] samples) throws Exception {
        return mean(samples, 0, samples.length);
    }/*from   www.  j a v  a2  s .c o m*/

    public static double mean(double[] samples, int fromIndex, int toIndex) throws Exception {
        if (samples.length == 0) {
            throw new Exception("Empty array to calculate mean");
        }
        if (fromIndex < 0 || fromIndex >= samples.length || toIndex < 0 || toIndex >= samples.length) {
            throw new IndexOutOfBoundsException();
        }
        double meanValue = 0;
        for (int i = fromIndex; i <= toIndex; i++) {
            meanValue += samples[i];
        }
        return meanValue / (toIndex - fromIndex + 1);
    }
}

Related

  1. mean(double[] data)
  2. mean(double[] data)
  3. mean(double[] doubleArray)
  4. mean(double[] list)
  5. mean(double[] nums)
  6. mean(double[] series)
  7. mean(double[] v)
  8. mean(double[] values)
  9. mean(double[] vector)