Java tutorial
//package com.java2s; //License from project: BSD License public class Main { public static void normalizeByAvg(double[] x) { double sum = 0; int n = 0; for (int i = 0; i < x.length; i++) if (!Double.isNaN(x[i])) { sum += x[i]; n++; } if (sum == 0) return; sum /= n; for (int i = 0; i < x.length; i++) if (!Double.isNaN(x[i])) x[i] -= sum; } }