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

intaverageX(long[][] intImg, int width, int height, int i, int j, int dl, int dr)
Compute the average x coordinate of nonzero pixels
int count = 0, sum = 0, xstart = Math.max(0, j - dl), xend = Math.min(width - 1, j + dr),
        ystart = Math.max(-1, i - dl), yend = Math.min(height - 1, i + dr);
for (int k = xstart; k < xend; k++) {
    int tmp = (int) (intImg[yend][k] - (ystart != -1 ? intImg[ystart][k] : 0)
            + (k != 0 ? -intImg[yend][k - 1] + (ystart != -1 ? intImg[ystart][k - 1] : 0) : 0));
    count += tmp;
    sum += tmp * k;
return count == 0 ? Integer.MAX_VALUE : sum / count;
floatavg(byte[] values)
The average of an array
return avg(values, 0, values.length);
doubleavg(double a, double b)
Returns the average of two doubles
return (a + b) / 2d;
doubleavg(double v1, double v2)
avg
return (v1 + v2) / 2.;
doubleavg(double values[], int size, boolean ignoreNan)
avg
if (values == null || size == 0) {
    return Double.NaN;
int cnt = 0;
double sum = 0;
for (int i = 0; i < size; i++) {
    double v = values[i];
    if (!Double.isNaN(v)) {
...
doubleavg(double... a)
avg
if (a == null) {
    return 0;
long count = a.length;
double sum = sum(a);
if (count > 0) {
    return sum / count;
} else {
...
doubleavg(double[] a)
Average or mean value of array
return sum(a) / (a.length);
doubleavg(double[] array)
avg
double sum = 0;
for (double val : array) {
    sum += val;
return sum / array.length;
doubleavg(double[] nums)
avg
double sum = 0;
for (double n : nums)
    sum += n;
return sum / nums.length;
doubleavg(double[] values)
Calculates the average over an given array of doubles.
double avg = 0;
for (double v : values) {
    avg += v;
return avg / values.length;