Java Array Normalize normalizeLengthInPlace(double[] in)

Here you can find the source of normalizeLengthInPlace(double[] in)

Description

normalize Length In Place

License

Apache License

Declaration

public static final void normalizeLengthInPlace(double[] in) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static final void normalizeLengthInPlace(double[] in) {
        double sum = (Math.sqrt(sumSquares(in)));
        for (int i = 0; i < in.length; i++) {
            in[i] = in[i] / sum;//from   w  w w  .java2 s. co  m
        }
    }

    public static final void normalizeLengthInPlace(float[] in) {
        float sum = (float) (Math.sqrt(sumSquares(in)));
        for (int i = 0; i < in.length; i++) {
            in[i] = in[i] / sum;
        }
    }

    public static final float sumSquares(float[] in) {
        float sum = 0;
        for (int i = 0; i < in.length; i++) {
            sum += (in[i] * in[i]);
        }
        return sum;
    }

    public static final double sumSquares(double[] in) {
        float sum = 0;
        for (int i = 0; i < in.length; i++) {
            sum += (in[i] * in[i]);
        }
        return sum;
    }
}

Related

  1. normalizeHistogram(int[] hist)
  2. normalizeHistogramToBase(int[] hist, double base)
  3. normalizeInnerPointDistanceMax(double[][] distances, double maxDist)
  4. normalizeL2(double[] a)
  5. normalizeL2(double[] histogram)
  6. normalizeLog(double[] logs)
  7. normalizeMatrix(double[][] M)
  8. normalizeMatrix(float[] cm)
  9. normalizeMemberNames(final String[] memberNames)