Here you can find the source of normaliseSum(double[] a)
Parameter | Description |
---|---|
a | The array to normalise (the values in this array are altered). |
public static double[] normaliseSum(double[] a)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from ww w. j a va2 s . c o m*/ * @param a The array to normalise (the values in this array are altered). * @return The given array with normalised values such that sum(a) will return 1. */ public static double[] normaliseSum(double[] a) { double sumInv = 1.0 / sum(a); for (int i = 0; i < a.length; i++) a[i] *= sumInv; return a; } /** * @param a The array to sum. * @return The sum over all elements in the array. */ public static double sum(double[] a) { double sum = 0; for (int i = 0; i < a.length; i++) sum += a[i]; return sum; } /** * @param a The array to sum. * @return The sum over all elements in the array. */ public static long sum(int[] a) { long sum = 0; for (int i = 0; i < a.length; i++) sum += a[i]; return sum; } }