Java Array Average average(float[][] data, int startIndex, int endIndex)

Here you can find the source of average(float[][] data, int startIndex, int endIndex)

Description

Calculates average vector

License

Open Source License

Parameter

Parameter Description
data a parameter
startIndex a parameter
endIndex a parameter

Declaration

public static float[] average(float[][] data, int startIndex,
        int endIndex) 

Method Source Code

//package com.java2s;
/*/*  ww  w.ja v  a  2  s .co m*/
 * Copyright (c) 2008-2013 Maksim Khadkevich and Fondazione Bruno Kessler.
 *
 * This file is part of MART.
 * MART is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2, as published
 * by the Free Software Foundation.
 *
 * MART is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with MART; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

public class Main {
    /**
     * Calculates average vector
     *
     * @param data
     * @param startIndex
     * @param endIndex
     * @return
     */
    public static float[] average(float[][] data, int startIndex,
            int endIndex) {
        if (data.length == 0) {
            return new float[] {};
        }
        float[] out = new float[data[startIndex].length];
        for (int i = startIndex; i < endIndex; i++) {
            for (int j = 0; j < out.length; j++) {
                out[j] += data[i][j] / (endIndex - startIndex + 1);
            }
        }
        return out;
    }
}

Related

  1. average(final double[] values)
  2. average(final Float... values)
  3. average(final float[] values)
  4. average(final int totalAmount, final int orderCount)
  5. average(final T p_num1, final T p_num2)
  6. average(float[][] originalValues, float[][] newValues, int[] indexArray)
  7. average(int argb0, int argb1)
  8. average(int... is)
  9. average(int... values)