Java Matrix Max Value maxIndices(double M[][])

Here you can find the source of maxIndices(double M[][])

Description

returns argmax_{j,k} M[j][k]

License

Open Source License

Declaration

public static int[] maxIndices(double M[][]) 

Method Source Code

//package com.java2s;
/*//from   w w  w  . j a  va 2s.c om
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * returns argmax_{j,k} M[j][k]
      */
    public static int[] maxIndices(double M[][]) {
        double max = Double.MIN_VALUE;
        int i_max = -1;
        int j_max = -1;
        for (int i = 0; i < M.length; i++) {
            for (int j = 0; j < M[i].length; j++) {
                if (M[i][j] > max) {
                    max = M[i][j];
                    i_max = i;
                    j_max = j;
                }
            }
        }
        return new int[] { i_max, j_max };
    }
}

Related

  1. max(float[][] a)
  2. max(float[][] originalValues, float[][] newValues, int[] indexArray, float value)
  3. max_abs(double[][] matrix)
  4. maxDifffer(double[][] pos)
  5. maxDistance(double[][] _values)
  6. maxInRowIndex(double[][] M, int row)
  7. maxtrixPermutation(int beforeArray[][])