Questions tagged [argmax]

arguments of the maxima: given a function of some arguments, argmax stands for the values of the arguments that maximizes the function.

Case 1

Here we consider a function f that maps from a limited set.

Say,

f(x) := {13, 42, 1981, 9, 11, 0},

so f(x = 1) = 13,and f(x = 2) = 42, so on.

It is easy to see here that the value of x that maximizes the function f is 3; that is f(x = 3) = 1981 is the highest values. Thus, argmax of f(x) is x = 3.

In R

f = c(13, 42, 1981, 9, 11, 0)
which.max(f)
# 3

Case 2

Here we consider a function of a continues variable.

Consider

f(x) = x(4 - x)

for this function the argmax is x = 2. That is the highest value of f(x) is 4 which corresponds to x = 2.

In R, we can use the optimize function for this to find the argmax of f.

f <- function(x) {
     x*(4 - x)
}

optimize(f, interval = c(-100, 100), maximum = TRUE)
# $maximum
# [1] 2
#
#$objective
#[1] 4
170 questions
0
votes
1 answer

How use argmax along axis to get maximum values in each column of numpy 2D array?

For example I have the following 2D array: array([[ 5.59635947, 1.42474555, 1.56519762], [ 6.16476541, 6.12324772, 5.32735447], [ 8.60258444, 7.16592582, 1.49555662], [ 0.63983973, 5.50249666, 3.52246942], […
0
votes
0 answers

Numpy argmax function error

I am trying to use the argmax function of numpy to take two argument. Here is the code: UP = 1 DOWN = 2 LEFT = 3 RIGHT = 4 actlist = [UP, DOWN, LEFT, RIGHT] a = numpy.argmax(actlist, lambda a: expected_utility(a,i,j,U)) The problem is, one of…
0
votes
1 answer

How to check if the argmax of a tensor is equal to any argmax of another tensor which has several equal max?

So usually in single label classification, we use the following correct_preds = tf.equal(tf.argmax(preds, 1), tf.argmax(self.label, 1)) But I am working with multi label classification so I'd like to know how to do that where there are several ones…
Tom
  • 275
  • 2
  • 16
0
votes
1 answer

Tensorflow: Indices of max value in 2x2 matrix across batch

If I have a batch of matrices such that my matrix is shape (?, 600, 600), how would I go about retrieving the row and col indices of the maximum value in each matrix in the batch? Such that my row and column return matrices are each of shape (?)…
Aneesh
  • 3
  • 2
0
votes
2 answers

Fetch values of other columns which have max value in given column

I can find max values of rows, disp, hp in mtcars dataset using sapply function, which gives 472 335 respectively: sapply(list(mtcars$disp,mtcars$hp), max, na.rm=TRUE) Now I want cyl for these values, i.e. cyl of cars where maximum value of…
Bhavana
  • 15
  • 4
0
votes
1 answer

How to use argmax tensorflow function in 3d array?

I want to know how to use tf.argmax in 3D array. My input data is like that: [[[0, -1, 5, 2, 1], [2, 2, 3, 2, 5], [6, 1, 2, 4, -1]], [[-1, -2, 3, 2, 1], [0, 3, 2, 7, -1], [-1, 5, 2, 1, 3]]] And I want to get the output of argmax by this input data…
Gi Yeon Shin
  • 357
  • 2
  • 7
  • 19
0
votes
1 answer

Argmax on a tensor and ceiling in Tensorflow

Suppose I have a tensor in Tensorflow that its values are like: A = [[0.7, 0.2, 0.1],[0.1, 0.4, 0.5]] How can I change this tensor into the following: B = [[1, 0, 0],[0, 0, 1]] In other words I want to just keep the maximum and replace it…
Rouzbeh
  • 2,141
  • 1
  • 11
  • 19
0
votes
1 answer

why we need tf.arg_max(Y,1) with softmax in tensorflow?

when I write the tensorflow demo, I find this arg_max() function in the definition of correct_predition cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits( logits=hypothesis,labels=Y)) optimizer =…
Hong Cheng
  • 318
  • 1
  • 4
  • 19
0
votes
1 answer

Numpy: filling the non-maximum elements of ndarray with zeros

I have a ndarray, and I want to set all the non-maximum elements in the last dimension to be zero. a = np.array([[[1,8,3,4],[6,7,10,6],[11,12,15,4]], [[4,2,3,4],[4,7,9,8],[41,14,15,3]], …
Vahid Mirjalili
  • 6,211
  • 15
  • 57
  • 80
0
votes
1 answer

Pandas idxmax() get column name corresponding to max value in row

Suppose I have the following DataFrame Q_df: (0, 0) (0, 1) (0, 2) (1, 0) (1, 1) (1, 2) (2, 0) (2, 1) (2, 2) (0, 0) 0.000 0.00 0.0 0.64 0.000 0.0 0.512 0.000 0.0 (0, 1) 0.000 0.00 0.8 0.00 0.512…
Kurt Peek
  • 52,165
  • 91
  • 301
  • 526
0
votes
2 answers

python pandas: computing argmax of column in matrix subset

Consider toy dataframes df1 and df2, where df2 is a subset of df1 (excludes the first row). import pandas as pd import numpy as np df1 = pd.DataFrame({'colA':[3.0,9,45,7],'colB':['A','B','C','D']}) df2 = df1[1:] Now lets find argmax of colA for…
bigO6377
  • 1,256
  • 3
  • 14
  • 28
0
votes
1 answer

NumPy argmax and structured array error: expected a readable buffer object

I got the following error while using NumPy argmax method. Could some one help me to understand what happened: import numpy as np b = np.zeros(1, dtype={'names':['a','b'], 'formats': ['i4']*2}) b.argmax() The error is TypeError: expected a…
Bin Zhou
  • 603
  • 2
  • 10
  • 17
0
votes
1 answer

Taking argmax over all axes except first

I have a numpy array and I'd like to take the argmax over all axes except the first. I have (I think) a solution, but I wonder whether there's a better way to do it. import numpy as np def argmax(array): ## Argmax along all axes except the…
Adrian
  • 3,138
  • 2
  • 28
  • 39
0
votes
1 answer

argmin/argmax with PyOpenCL

How would I write argmin or argmax with PyOpenCL? I figure I would need to calculate the argmin/min for each workgroup, and then reduce these using subsequent invocations.
Neil G
  • 32,138
  • 39
  • 156
  • 257
-1
votes
1 answer

Calculating the argmax from one array and using to get values from another

I am trying to get the argmax from one ndaray and use it to get values from another ndarray, but I am doing something wrong. ndvi_array = np.random.randint(0, 255, size=(4, 1, 100, 100)) image_array = np.random.randint(0, 255, size=(4, 12, 100,…
Vitaly Olegovitch
  • 3,509
  • 6
  • 33
  • 49
1 2 3
11
12