Java Array Normalize normalize(double[] ar)

Here you can find the source of normalize(double[] ar)

Description

Returns a new array which has the numbers in the input array L1-normalized.

License

Open Source License

Parameter

Parameter Description
ar Input array

Return

New array that has L1 normalized form of input array

Declaration

public static double[] normalize(double[] ar) 

Method Source Code

//package com.java2s;

public class Main {
    /** Returns a new array which has the numbers in the input array
     *  L1-normalized./*  www  .  ja  v a2  s. co  m*/
     *
     *  @param ar Input array
     *  @return New array that has L1 normalized form of input array
     */
    public static double[] normalize(double[] ar) {
        double[] ar2 = new double[ar.length];
        double total = 0.0;
        for (double d : ar) {
            total += d;
        }
        for (int i = 0; i < ar.length; i++) {
            ar2[i] = ar[i] / total;
        }
        return ar2;
    }
}

Related

  1. normalize(double[] a)
  2. normalize(double[] a)
  3. normalize(double[] a)
  4. normalize(double[] a)
  5. normalize(double[] a)
  6. normalize(double[] array)
  7. normalize(double[] array)
  8. normalize(double[] array)
  9. normalize(double[] bins)