Java Utililty Methods Array Average

List of utility methods to do Array Average

Description

The list of methods to do Array Average are organized into topic(s).

Method

doubleaverage(long[] array)
Returns the average value of an array.
return array.length == 0 ? 0 : sum(array) / array.length;
doubleaverage(long[] vals)
average
long sum = 0;
double n = (double) vals.length;
for (Long i : vals)
    sum += ((double) i);
return sum / n;
Numberaverage(Number[] numbers)
Calculates the average, and returns it in the correct class.
Number sum = sum(numbers);
return divide(sum, new Integer(numbers.length));
doubleaverage1(double[] d)
average
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++;
...
doubleaverage2(double[] d)
average
if (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++;
...
intaverage4RGBA(int var0, int var1, int var2, int var3)
average RGBA
int var4 = var0 & 255;
int var5 = var1 & 255;
int var6 = var2 & 255;
int var7 = var3 & 255;
switch (var4 << 24 | var5 << 16 | var6 << 8 | var7) {
case -16777216:
    return var0;
case -16776961:
...
float[]averageChroma(float[] chromaSums, int countChromas)
average Chroma
float[] resultChroma = new float[12];
for (int i = 0; i < chromaSums.length; i++) {
    resultChroma[i] = chromaSums[i] / countChromas;
return resultChroma;
doubleaverageLuminance(double[] luminance)
average Luminance
double avgLum = 0;
for (double element : luminance) {
    avgLum += element;
avgLum = avgLum / luminance.length;
return avgLum;
doubleaverageNonZeros(int[] array)
Returns the average value only among non-zero values
if (array.length == 0)
    return 0;
int numNonZeros = 0;
double sum = 0;
for (int i = 0; i < array.length; i++) {
    if (array[i] != 0) {
        sum += array[i];
        numNonZeros++;
...
double[]averagePt(double[][] ndPoints)
Find the average n-d point in a collection of n-d points.
int nDimensions = ndPoints[0].length;
double[] avg = new double[nDimensions];
for (double[] ndPoint : ndPoints) {
    for (int n = 0; n < nDimensions; n++) {
        avg[n] += ndPoint[n];
for (int n = 0; n < nDimensions; n++) {
...