Compute the mean of a vector. - Java java.lang

Java examples for java.lang:Math Matrix

Description

Compute the mean of a vector.

Demo Code


//package com.java2s;

public class Main {
    /**/*  w ww  .  ja v a  2 s.  com*/
     * Compute the mean of a vector.
     */
    public static double getMean(double[] data) {
        double sum = 0.0;
        for (int i = 0; i < data.length; i++) {
            sum += data[i];
        }
        return sum / (double) data.length;
    }
}

Related Tutorials