Java Matrix Sum sumSq(float[][] arr)

Here you can find the source of sumSq(float[][] arr)

Description

Calculate the sum of the squared values of a 2D array.

License

Open Source License

Parameter

Parameter Description
arr a parameter

Return

sum of squares

Declaration

public static float sumSq(float[][] arr) 

Method Source Code

//package com.java2s;

public class Main {
    /**//w  w  w .  j  av  a 2 s .co  m
     * Calculate the sum of the squared values of a 2D array.
     * 
     * @param arr
     * @return sum of squares
     */
    public static float sumSq(float[][] arr) {
        float sum = 0;
        for (int i = 0; i < arr.length; i++)
            sum += sumSq(arr[i]);
        return sum;
    }

    /**
     * Calculate the sum the squared values of a 1D array.
     * 
     * @param arr
     * @return sum of squares
     */
    public static float sumSq(float[] arr) {
        float sum = 0;
        for (int i = 0; i < arr.length; i++)
            sum += arr[i] * arr[i];
        return sum;
    }
}

Related

  1. sumOfMatrixElements(double[][] m)
  2. sumRow(int[][] matrix, int u)
  3. sumRow(int[][] table, int column)
  4. sums(double[][] input)
  5. sumSpecificIndices(double[] input, int[][] indices, int columnInIndices)