Java Matrix Sum sumDimension(double[][] matrix, int dim)

Here you can find the source of sumDimension(double[][] matrix, int dim)

Description

sum Dimension

License

Open Source License

Declaration

public static double[] sumDimension(double[][] matrix, int dim) 

Method Source Code

//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;
    }
}

Related

  1. sum(int[][][] X, int[] coords)
  2. sumArrayDim(double[][] array, int dimToSummarize)
  3. sumArrays(double a[][], double b[][], String sign)
  4. sumAxis1(double[][] X)
  5. sumCols(boolean[][] inputMatrix)
  6. SumIntegrateHistogram_25(float[][][] histo_array)
  7. sumLines(double a[][])
  8. sumMetrix(double[][] total, double[][] element)
  9. sumOfMatrixElements(double[][] m)