Java Array Average averagePt(double[][] ndPoints)

Here you can find the source of averagePt(double[][] ndPoints)

Description

Find the average n-d point in a collection of n-d points.

License

Open Source License

Parameter

Parameter Description
ndPoints a bunch of n-d points

Return

the average nd point. Note this is just the actual average, it may not be a real point resolve the input ndPoints.

Declaration

public static double[] averagePt(double[][] ndPoints) 

Method Source Code

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

public class Main {
    /**//from  www  .  jav a2 s. c  o m
     * Find the average n-d point in a collection of n-d points.
     * @param ndPoints a bunch of n-d points
     * @return the average nd point. Note this is just the actual average,
     * it may not be a real point resolve the input ndPoints.
     */
    public static double[] averagePt(double[][] ndPoints) {
        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++) {
            avg[n] /= ndPoints.length;
        }
        return avg;
    }
}

Related

  1. average1(double[] d)
  2. average4RGBA(int var0, int var1, int var2, int var3)
  3. averageChroma(float[] chromaSums, int countChromas)
  4. averageLuminance(double[] luminance)
  5. averageNonZeros(int[] array)
  6. averageX(long[][] intImg, int width, int height, int i, int j, int dl, int dr)
  7. avg(byte[] values)
  8. avg(double a, double b)
  9. avg(double v1, double v2)