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
2 answers

How to return the positions of the maximum value in an array

As stated I want to return the positions of the maximum value of the array. For instance if I have the array: A = np.matrix([[1,2,3,33,99],[4,5,6,66,22],[7,8,9,99,11]]) np.argmax(A) returns only the first value which is the maximum, in this case…
Harry Spratt
  • 179
  • 11
0
votes
1 answer

TypeError: data type not understood in numpy

I was working with numpy for Neural Networks and I am facing This Error TypeError: data type not understood and my code was a = np.array([7, 7, 7], [7, 7, 7]) print(np.argmax(np.array([[5, 6, 7], [1, 2, 3]]), axis = 0, a))
0
votes
2 answers

argmax() doesn't show timestamped index only index number

I have a small dataframe like below: Here is the code: my_dates = [datetime(2016, 1, 1), datetime(2016, 1, 2), datetime(2016,1,3)] dt_ind = pd.DatetimeIndex(my_dates) data = [2,8,15] cols = ['num'] df = pd.DataFrame(data,dt_ind,cols) I am trying…
Jinni
  • 1
  • 1
0
votes
0 answers

KFold function TypeError: reduction operation 'argmax' not allowed for this dtype

I defined a function to print K fold scores and determine the best c but I'm getting an error in this line in the code below(I've highlighted the line in the code as well): best_c = results_table.loc[results_table['Mean recall…
Mrigank
  • 1
  • 1
0
votes
1 answer

Numpy Argmax Over Multiple Axes for an Array Slice

Suppose that I have an array which has mxn dimensions. How do I do the argmax using numpy over the last n dimensions? So the output array should, given the first m indices, return a list of n indices that correspond the the maximal value of array[m…
Light
  • 31
  • 3
0
votes
1 answer

How to get the argmax of last 2 axes?

Let's say I have an array which it's dimensions are 10 X 20 X 12 X 12 X 2 X 2. What should I do if I want to get the maximum values indices of the last two axes? meaning I want a function which will output (if the described array is the input) an…
user10794514
0
votes
0 answers

How to solve this quadratic optimization problem in R?

I am currently trying to implement a bigger simulation exercise but i'm stuck with this bit. The aim is to find the vector p* (2x1) that maximizes this function (p* = argmax of h): Equation Also Y and q are given and all other quantities in the…
ank13
  • 1
  • 1
0
votes
1 answer

How to make np.ma.argmin return None if every element is masked?

Motivation: in a list of numeric values I try to find the index of the smallest value - with the side condition, that the value has to below a certain treshold. Here is an example where everything works as expected import numpy as np a =…
Qaswed
  • 3,649
  • 7
  • 27
  • 47
0
votes
2 answers

In R, how can I use argmax function by row and count the variable number?

I have the raw dataset. The below is sample of raw data: sentiment pos neu neg likes_count 1 1 0 0 5 2 0.2 0.3 0.5 6 3 0.3 0.3 0.4 6 4 0 0 1 3 5 …
user12388610
  • 167
  • 1
  • 11
0
votes
2 answers

How to use argmin and argmax functions over a np.matrix element in python?

I have the following situation. Let's define a D (8,4) matrix : import numpy as np import random D=np.matrix([[72 22 58 63] [28 22 32 20] [40 41 58 20] [22 58 22 41] [28 78 51 45] [58 61…
0
votes
2 answers

Printing index of numpy array with max

I want to print out the index of an array that has the maximum value (and since indexing begins at 0, I need to add one to the index value to get 1-indexed). Example: rslt = np.amax(final_array) print("The maximum value is :", rslt) print("The…
0
votes
1 answer

Pytorch: How plot the prediction output from segmentation task when batch size is larger than 1?

I have a doubt and a question about plot output of different batches in segmentation subject. The snippet below plot the probability of each class and the prediction output. I am sure the prob plots is plotting one batch, but not sure about…
AI_NA
  • 336
  • 2
  • 5
  • 20
0
votes
1 answer

Numpy argmax on multiple axes determined by other vectors

Say I have a 3d matrix called A with shape (100,4,100). And also two vectors of 200 values each, created like this: b = np.random.randint(0, 3, 200) c = np.random.randint(0, 99, 200) How can I efficiently find the argmax for each of A[b,c,:]? I am…
brad
  • 930
  • 9
  • 22
0
votes
1 answer

How can the function numpy.argmax() handle a list with numbers and characters

How can I determine the row with the highest value in index=0 even if index=1 is a character? I have an array of lists with two positions, where the first position is a number and the second position is a…
Bryan McGill
  • 237
  • 1
  • 2
  • 8
0
votes
2 answers

reduce_max function in tensorflow

Screenshot >>> boxes = tf.random_normal([ 5]) >>> with s.as_default(): ... s.run(boxes) ... s.run(keras.backend.argmax(boxes,axis=0)) ... s.run(tf.reduce_max(boxes,axis=0)) ... array([ 0.37312034, -0.97431135, 0.44504794, 0.35789603, …
Bubesh p
  • 65
  • 1
  • 8