Here you can find the source of sumDimension(double[][] matrix, int dim)
public static double[] sumDimension(double[][] matrix, int dim)
//package com.java2s; //License from project: GNU General Public License public class Main { public static double[] sumDimension(double[][] matrix, int dim) { if (dim == 1) { double[] sum = new double[matrix[0].length]; for (int s = 0; s < sum.length; s++) { for (int i = 0; i < matrix.length; i++) { sum[s] += matrix[i][s]; }//from w w w . j a va 2 s.c o m } return sum; } else if (dim == 2) { double[] sum = new double[matrix.length]; for (int s = 0; s < sum.length; s++) { for (int i = 0; i < matrix[0].length; i++) { sum[s] += matrix[s][i]; } } return sum; } else return null; } }