Java mean meanWithoutZeros(int[] in, int x1, int x2)

Here you can find the source of meanWithoutZeros(int[] in, int x1, int x2)

Description

mean Without Zeros

License

Open Source License

Declaration

static public double meanWithoutZeros(int[] in, int x1, int x2) 

Method Source Code

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

public class Main {
    static public double meanWithoutZeros(int[] in, int x1, int x2) {
        double res = 0;
        int k = 0;
        for (int i = x1; i < Math.min(in.length, x2); i++) {
            if (in[i] != 0) {
                res += in[i];//  w ww. ja v a  2  s .  com
                k++;
            }
        }
        return (1.0 * res) / k;
    }

    static public int min(int[] in, int x1, int x2) {

        int minval = 999999;

        if (in != null && x1 >= 0) {

            for (int i = x1; i < Math.min(in.length, x2); i++) {

                if (in[i] != 0)
                    minval = Math.min(in[i], minval);

            }
        }

        return minval;

    }

    static public int min(int[] in) {

        int minval = 999999;

        if (in != null) {

            for (int i = 0; i < in.length; i++) {

                if (in[i] != 0)
                    minval = Math.min(in[i], minval);

            }
        }

        return minval;

    }
}

Related

  1. meanSlow(final double[] values)
  2. meanSml(final int a, final int b)
  3. meanSquare(float[] a, int off, int length)
  4. meanSquaredError(double[] x, double[] y)
  5. meanSquaredError(double[][] vectorBatch1, double[][] vectorBatch2)
  6. meanWithoutZerosCentered(int[] in, int center, int width)
  7. std(double[] a, double mean, boolean isUnbiasedEstimator)
  8. std(double[] a, int size, double mean)
  9. std(double[] array, double mean)