Java Utililty Methods Matrix Sum

List of utility methods to do Matrix Sum

Description

The list of methods to do Matrix Sum are organized into topic(s).

Method

double[]sumArrayDim(double[][] array, int dimToSummarize)
add the number of elements in one dimension together E.g., from 2D array [[1],[2]] [[3],[4]] [[5],[6]] dim0size = 3, dim1size=2 sumArrayDim(array,0) should return array with size dim1size 2 [9=1+3+5, 12=2+4+6] sumArrayDim(array,1) should return array with size dim1size 3 [3=1+2, 7=3+4, 11=5+6]
double[] sum = null;
int dim0size = array.length;
int dim1size = array[0].length;
if (dimToSummarize == 0)
    sum = new double[dim1size];
else
    sum = new double[dim0size];
for (int i = 0; i < dim0size; i++) {
...
double[][]sumArrays(double a[][], double b[][], String sign)
Sum of the values in the array.
int H = a.length;
int W = a[0].length;
double out[][] = new double[H][W];
if (sign == "+") {
    for (int j = 0; j < W; j++) {
        for (int i = 0; i < H; i++) {
            out[i][j] = a[i][j] + b[i][j];
} else {
    for (int j = 0; j < W; j++) {
        for (int i = 0; i < H; i++) {
            out[i][j] = a[i][j] - b[i][j];
return out;
double[]sumAxis1(double[][] X)
sum Axis
int n = X.length;
double[] array = new double[n];
for (int i = 0; i < n; i++) {
    double[] x = row(X, i);
    array[i] = sum(x);
return array;
int[]sumCols(boolean[][] inputMatrix)
sum Cols
int g = inputMatrix.length;
int m = inputMatrix[0].length;
int[] sumMatrix = new int[m];
int i;
for (int j = 0; j < m; j++) {
    sumMatrix[j] = 0;
    for (i = 0; i < g; i++) {
        if (inputMatrix[i][j])
...
double[]sumDimension(double[][] matrix, int dim)
sum Dimension
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];
    return sum;
...
float[]SumIntegrateHistogram_25(float[][][] histo_array)
Get I and sigI by integrating the data in the histo_array using 25 slices, centered on the peak.
int n_pages = histo_array.length;
float[] sums = new float[n_pages];
for (int page = 0; page < n_pages; page++) {
    sums[page] = 0;
    float[][] arr = histo_array[page];
    for (int row = 0; row < histo_array[0].length; row++)
        for (int col = 0; col < histo_array[0][0].length; col++)
            sums[page] += arr[row][col];
...
double[]sumLines(double a[][])
sum Lines
double[] res = new double[a.length];
for (int i = 0; i < a.length; i++) {
    res[i] = sum(a[i]);
return res;
voidsumMetrix(double[][] total, double[][] element)
sum Metrix
for (int i = 0; i < element.length; i++) {
    for (int j = 0; j < element[0].length; j++) {
        total[i][j] = total[i][j] + element[i][j];
doublesumOfMatrixElements(double[][] m)
sum Of Matrix Elements
double sum = 0;
for (int i = 0; i < m.length; i++)
    for (int j = 0; j < m[0].length; j++)
        sum += m[i][j];
return sum;
doublesumRow(int[][] matrix, int u)
sum Row
double a = 0.0D;
for (int m = 0; m < matrix[u].length; m++) {
    a += matrix[u][m];
return a;