Here you can find the source of normalize(int[] values)
public static float[] normalize(int[] values)
//package com.java2s; import java.util.Arrays; public class Main { /**//ww w . j a va 2 s . c o m * Normalizes an array of integers from the bounding [min,max] to * [0.0, 1.0]. If min == max, all elements in the returned array * will be 1f. */ public static float[] normalize(int[] values) { // Allocate storage for the normalized array float[] normalized = new float[values.length]; // Determine the minimum and maximum int min = getMinValue(values); int max = getMaxValue(values); int spread = max - min; // If there is no spread, return a flat normalization if (spread == 0) { Arrays.fill(normalized, 1f); return normalized; } // Normalize each value in the input array for (int i = 0; i < values.length; i++) { normalized[i] = (values[i] - min) / (float) spread; } return normalized; } /** * Returns the minimum value in the given array of values, or {@link * Integer#MAX_VALUE} if the array is null or zero-length. */ public static int getMinValue(int[] values) { int min = Integer.MAX_VALUE; int vcount = (values == null) ? 0 : values.length; for (int ii = 0; ii < vcount; ii++) { if (values[ii] < min) { // new min min = values[ii]; } } return min; } /** * Returns the maximum value in the given array of values, or {@link * Integer#MIN_VALUE} if the array is null or zero-length. */ public static int getMaxValue(int[] values) { int max = Integer.MIN_VALUE; int vcount = (values == null) ? 0 : values.length; for (int ii = 0; ii < vcount; ii++) { if (values[ii] > max) { // new max max = values[ii]; } } return max; } }