Java Array Normalize normalize(float[] in)

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

Description

normalize

License

GNU General Public License

Declaration

public static float[] normalize(float[] in) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w .j  av a2 s .  c  o m*/
CCH World Factory - GPL
    
Copyright (C) 2014 Christopher Collin Hall
email: explosivegnome@yahoo.com
    
CCH World Factory - GPL is distributed under the GNU General Public 
License (GPL) version 3. A non-GPL branch of the CCH World Factory 
also exists. For non-GPL licensing options, contact the copyright 
holder, Christopher Collin Hall (explosivegnome@yahoo.com). 
    
CCH World Factory - GPL is free software: you can redistribute it 
and/or modify it under the terms of the GNU General Public License 
as published by the Free Software Foundation, either version 3 of 
the License, or (at your option) any later version.
    
CCH World Factory - GPL is distributed in the hope that it will be 
useful, but WITHOUT ANY WARRANTY; without even the implied warranty 
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
    
You should have received a copy of the GNU General Public License
along with CCH World Factory - GPL.  If not, see 
<http://www.gnu.org/licenses/>.
    
*/

public class Main {
    public static float[] normalize(float[] in) {
        float[] out = new float[in.length];
        float sum = 0;
        for (int i = 0; i < in.length; i++) {
            sum += in[i] * in[i];
        }
        sum = (float) Math.sqrt(sum);
        for (int i = 0; i < in.length; i++) {
            out[i] = in[i] / sum;
        }
        return out;
    }
}

Related

  1. normalize(final double[] vec)
  2. normalize(final double[] vector, final double[] minima, final double[] maxima)
  3. normalize(float p[])
  4. normalize(float[] data)
  5. normalize(float[] in)
  6. normalize(float[] input)
  7. normalize(float[] v)
  8. normalize(float[] vec)
  9. normalize(float[][] vals, float min, float max)