code: public static void standardize(double[][] x) {
          int n = x.length;
          int p = x[0].length;
  
          double[] center = colMeans(x);
          for (int i = 0; i < n; i++) {
              for (int j = 0; j < p; j++) {
                  x[i][j] = x[i][j] - center[j];
              }
          }
  
          double[] scale = new double[p];
          for (int j = 0; j < p; j++) {
              for (int i = 0; i < n; i++) {
                  scale[j] += Math.sqr(x[i][j]);
              }
              scale[j] = Math.sqrt(scale[j] / (n-1));
  
              if (!Math.isZero(scale[j])) {
                  for (int i = 0; i < n; i++) {
                      x[i][j] /= scale[j];
                  }
              }
          }
      }
docs: Standardizes each column of a matrix to 0 mean and unit variance.