Java Array Normalize normalizeRows(float[][] input)

Here you can find the source of normalizeRows(float[][] input)

Description

Normalizes each row in a matrix, in place.

License

Open Source License

Declaration

public static void normalizeRows(float[][] input) 

Method Source Code

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

public class Main {
    /**//from  w w  w . j a  v a  2 s  .  c  o m
     * Normalizes each row in a matrix, in place.
     */
    public static void normalizeRows(float[][] input) {
        for (int i = 0; i < input.length; ++i) {
            normalize(input[i]);
        }
    }

    /**
     * Normalizes the given input in place to make it unit length.
     */
    public static void normalize(float[] input) {
        double normSq = 0;
        for (int i = 0; i < input.length; ++i) {
            normSq += input[i] * input[i];
        }
        float norm = (float) Math.sqrt(normSq);
        for (int i = 0; i < input.length; ++i) {
            input[i] = input[i] / norm;
        }
    }
}

Related

  1. normalizeMatrix(float[] cm)
  2. normalizeMemberNames(final String[] memberNames)
  3. normalizePositiveValues(double[][] array)
  4. normalizeProb(double[] prob)
  5. normalizeRecorderColumn(int column, int tabSize, int[] tabIndices)
  6. normalizeSpaces(char[] buf, int origStart, int origEnd)
  7. normalizeTo(float[] in, float normsum)
  8. normalizeToInPlace(double[] in, double normsum)
  9. normalizeToLogProbs(double[] x)