Here you can find the source of argmax(final double[] vec)
Parameter | Description |
---|---|
vec | the vector to find the argmax of |
public static int argmax(final double[] vec)
//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; } }