Java mean mean(double[] a, double[] b)

Here you can find the source of mean(double[] a, double[] b)

Description

average two identical double array

License

Open Source License

Parameter

Parameter Description
a a parameter
b a parameter

Declaration

public static double[] mean(double[] a, double[] b) 

Method Source Code

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

public class Main {
    /**/*from www  .ja v  a  2  s .com*/
     * average two identical double array
     *
     * @param a
     * @param b
     * @return
     */
    public static double[] mean(double[] a, double[] b) {
        int n = Math.min(a.length, b.length);
        double[] ret = new double[a.length];
        for (int i = 0; i < n; i++) {
            ret[i] = (a[i] + b[i]) / 2.0;
        }
        return ret;
    }

    public static double mean(double[] d) {
        return sum(d) / d.length;
    }

    public static int mean(int[] d) {
        return sum(d) / d.length;
    }

    public static float mean(float[] d) {
        return sum(d) / d.length;
    }

    public static long mean(long[] d) {
        return sum(d) / d.length;
    }

    public static double sum(double[] d) {
        double ret = 0;
        for (int i = 0; i < d.length; i++) {
            ret += d[i];
        }
        return ret;
    }

    public static double sum(double[][] d) {
        double ret = 0;
        for (int i = 0; i < d.length; i++) {
            for (int j = 0; j < d[0].length; j++) {
                ret += d[i][j];
            }
        }
        return ret;
    }

    public static double sum(double[] d, int n) {
        double ret = 0;
        for (int i = 0; i < n; i++) {
            ret += d[i];
        }
        return ret;
    }

    public static int sum(int[] d) {
        int ret = 0;
        for (int i = 0; i < d.length; i++) {
            ret += d[i];
        }
        return ret;
    }

    public static float sum(float[] d) {
        float ret = 0;
        for (int i = 0; i < d.length; i++) {
            ret += d[i];
        }
        return ret;
    }

    public static long sum(long[] d) {
        long ret = 0;
        for (int i = 0; i < d.length; i++) {
            ret += d[i];
        }
        return ret;
    }
}

Related

  1. mean(double values[])
  2. mean(Double[] a)
  3. mean(double[] a)
  4. mean(double[] a)
  5. mean(double[] a)
  6. mean(double[] a, double[] b)
  7. mean(double[] a, int from, int to)
  8. mean(double[] a, int n)
  9. mean(double[] aArray)