Java Array Normalize normalizeTo(float[] in, float normsum)

Here you can find the source of normalizeTo(float[] in, float normsum)

Description

normalize To

License

Apache License

Declaration

public static final float[] normalizeTo(float[] in, float normsum) 

Method Source Code

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

public class Main {
    public static final float[] normalizeTo(float[] in, float normsum) {
        float sum = 0;
        float[] out = new float[in.length];
        for (int i = 0; i < in.length; i++) {
            sum += in[i];/*from w w w  .j  a va2s  . co m*/
        }
        for (int i = 0; i < in.length; i++) {
            out[i] = normsum * in[i] / sum;
        }
        return out;
    }

    public static final double[] normalizeTo(double[] in, double normsum) {
        double sum = 0;
        double[] out = new double[in.length];
        for (int i = 0; i < in.length; i++) {
            sum += in[i];
        }
        for (int i = 0; i < in.length; i++) {
            out[i] = normsum * in[i] / sum;
        }
        return out;
    }
}

Related

  1. normalizePositiveValues(double[][] array)
  2. normalizeProb(double[] prob)
  3. normalizeRecorderColumn(int column, int tabSize, int[] tabIndices)
  4. normalizeRows(float[][] input)
  5. normalizeSpaces(char[] buf, int origStart, int origEnd)
  6. normalizeToInPlace(double[] in, double normsum)
  7. normalizeToLogProbs(double[] x)
  8. normalizeToOne(double[] doubles)
  9. normalizeToSumUpTo(double[] x, double sumUp)