Java Array Max Value argmax(final double[] vec)

Here you can find the source of argmax(final double[] vec)

Description

Returns the index of the greatest element in a vector.

License

Open Source License

Parameter

Parameter Description
vec the vector to find the argmax of

Return

the argmin of vec

Declaration

public static int argmax(final double[] vec) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   w  ww.  j av a  2  s  .c  o m*/
     * Returns the index of the greatest element in a vector.
     * Precondition : vec != null
     * @param vec    the vector to find the argmax of
     * @return the argmin of vec
     */
    public static int argmax(final double[] vec) {
        assert (vec != null);
        double max = vec[0];
        int argmax = 0;
        for (int i = 1; i < vec.length; i++) {
            final double tmp = vec[i];
            if (tmp > max) {
                max = tmp;
                argmax = i;
            }
        }
        return argmax;
    }
}

Related

  1. argmax(double[] array, boolean naturalNumbers)
  2. argmax(double[] weights)
  3. argmax(float[] args)
  4. argMax(int[] a)
  5. argmax(int[] a)
  6. argmax(int[] array)