Here you can find the source of average1(double[] d)
Parameter | Description |
---|---|
d | a parameter |
public static double average1(double[] d)
//package com.java2s; //License from project: Open Source License public class Main { /**/* w w w . ja v a2s .co m*/ * * @param d * @return */ public static double average1(double[] d) { // Schneller if (d == null || d.length < 1) return Double.NaN; double retVal = 0; int countNonNAN = 0; for (int i = 0; i < d.length; i++) { if (Double.isNaN(d[i]) || Double.isInfinite(d[i])) continue; countNonNAN++; retVal += d[i]; } if (countNonNAN <= 0) return Double.NaN; return (retVal / countNonNAN); } /** * * @param d * @return */ public static double[] average1(double[][] d) { // Schneller if (d.length < 1) return new double[0]; double[] retVal = null; int countNonNull = 0; for (int i = 0; i < d.length; i++) { if (d[i] == null) continue; // kommt vor wenn er sequenz i nicht mappen kann countNonNull++; if (retVal == null) retVal = new double[d[i].length]; for (int j = 0; j < d[i].length; j++) retVal[j] += d[i][j]; } if (retVal == null) return null; // Koomt vor wenn er alle sequenzen nicht mappen kann for (int i = 0; i < retVal.length; i++) retVal[i] /= countNonNull; return retVal; } }