Java mean mean(final double[] vec)

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

Description

Computes the mean of the elements of a vector.

License

Open Source License

Parameter

Parameter Description
vec the vector.

Return

the mean of the elements of the vector.

Declaration

public static double mean(final double[] vec) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*  ww  w .j a  v  a  2s. c  o m*/
    * Computes the mean of the elements of a vector.
    * @param vec   the vector.
    * @return       the mean of the elements of the vector.
    */
    public static double mean(final double[] vec) {
        assert vec != null;

        return sum(vec) / vec.length;
    }

    /**
    * Computes the sum of the elements of a vector.
    * @param array  the array, to be summed.
    * @return       the sum of the elements of the vector.
    */
    public static double sum(final double[] vec) {
        assert vec != null;

        double s = 0;
        for (double i : vec) {
            s += i;
        }
        return s;
    }
}

Related

  1. mean(final double[] a)
  2. mean(final double[] data, final boolean noNaN)
  3. mean(final double[] expected, final int begin, final int end)
  4. mean(final double[] in, final int start, final int stop)
  5. mean(final double[] values)
  6. mean(final int[] scores)
  7. mean(final int[] values)
  8. mean(float a, float b)
  9. mean(float[] a, int off, int length)