Java Array Normalize normalizeComponentsOverwrite(float[][][][] in)

Here you can find the source of normalizeComponentsOverwrite(float[][][][] in)

Description

normalize Components Overwrite

License

Apache License

Declaration

public static final void normalizeComponentsOverwrite(float[][][][] in) 

Method Source Code

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

public class Main {
    public static final void normalizeComponentsOverwrite(float[][][][] in) {
        int nx = in.length;
        int ny = in[0].length;
        int nz = in[0][0].length;
        int nc = in[0][0][0].length;
        float lensqr = -1;
        for (int x = 0; x < nx; x++)
            for (int y = 0; y < ny; y++)
                for (int z = 0; z < nz; z++) {
                    lensqr = sumSquares(in[x][y][z]);
                    if (lensqr > 0) {
                        for (int c = 0; c < nc; c++) {
                            in[x][y][z][c] = (float) (in[x][y][z][c] / Math.sqrt(lensqr));
                        }/*from w w w.jav  a 2 s. c  o  m*/
                    }
                }
    }

    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. normalizeArray(double[] hist)
  2. normalizeArray(String[] raw, int expectedSize)
  3. normalizeArrays(int normalizeToLength, String[]... arraysToNormalize)
  4. normalizeCharacterData(char[] ch, int start, int length)
  5. normalizeComplexVectorsToUnitVectors(float[] complex)
  6. normalizeContingencyTable(final int[][] table)
  7. normalizeCoordsSum(float[] vector, float newSum)
  8. normalizedBySum(double[] values)
  9. normalizedTermMu(double ui, double[] uis)