Java Array Min Value argmin(final double[] vec)

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

Description

Returns the index of the smallest element in a vector.

License

Open Source License

Parameter

Parameter Description
vec the vector to find the argmin of

Return

the argmin of vec

Declaration

public static int argmin(final double[] vec) 

Method Source Code

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

public class Main {
    /**//from ww  w.  j  a  v a  2 s.  co m
     * Returns the index of the smallest element in a vector.
     * Precondition : vec != null
     * @param vec    the vector to find the argmin of
     * @return the argmin of vec
     */
    public static int argmin(final double[] vec) {
        assert vec != null;

        double min = vec[0];
        int argmin = 0;
        for (int i = 1; i < vec.length; i++) {
            final double tmp = vec[i];
            if (tmp < min) {
                min = tmp;
                argmin = i;
            }
        }
        return argmin;
    }
}

Related

  1. argmin(double... vs)
  2. argmin(int[] a)
  3. argMin(int[] a)
  4. arrayMin(double minVal, double[] vals)
  5. arrayMin(double[] arr)