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
1
vote
0 answers

How to calculate argmax in MATLAB?

Argmax: https://en.wikipedia.org/wiki/Arg_max Since there was some confusion i will describe what argmax does: argmax finds arguments for a function so that this function is maximized. Simple example: x * (10 - x) x = 1 -> 1 * (10 - 1) = 9 x = 2 ->…
Spenhouet
  • 6,556
  • 12
  • 51
  • 76
1
vote
2 answers

Find row-index of highest value in given column of dataframe

I want to order a DataFrame by increasing value of column number, and get the indexof that highest value. (Here it's the second row, so the result should be 'BCD': number L-word ID ABC 1 Lord ABC works BCD 25 Land BCD works CDE 3 …
Maik Ro
  • 320
  • 1
  • 11
1
vote
2 answers

`Pandas argmax` to get all `True` indices after masking (Python 3) (e.g. (pd.Series > 0).argmax()))

What I want to do but argmax only gives me the first value that is True: Se = pd.Series(np.arange(6), index=list("abcdef")) #a 0 #b 1 #c 2 #d 3 #e 4 #f 5 #dtype: int64 mask = (Se % 2 == 0) #a True #b False #c True #d …
O.rka
  • 29,847
  • 68
  • 194
  • 309
1
vote
2 answers

first occurence of a value greater than given in numpy array

I have a 2D array like: r1= np.array([[1,2,3,4],[2,3,4,5],[3,4,5,6]]) I need to find , for each row, the first occurence of a value greater than a default value. I am using this: default=2 ans= np.argmax(r1>default,1) The issue is that it works if…
dayum
  • 1,073
  • 15
  • 31
1
vote
0 answers

Python numba: how to find position of the largest element in array

I'm writing a code for real-time processing of an image from a camera. I am using Python 3.5 with Anaconda Accelerate/Numba packages to perform most of the calculations on the GPU. I have problems with implementing a function which will find the…
1
vote
1 answer

Python - argmin / argmax for member function

I would like to know if there is a "pythonic" way to use the mathematical argmin/argmax for a member function without using library like numpy. I have a class with a member function inside which returns an integer. I instantiate several objects of…
Manu NALEPA
  • 1,356
  • 1
  • 14
  • 23
1
vote
1 answer

Mathematica: FindArgMax does not return a global maximum

I have a fairly highly oscillating function, and I need to find the ArgMax in the interval (-Pi,Pi). When I Plot the function it is clear that FindArgMax picks the wrong maximum. I have tried adjusting AccuracyGoal and PrecisionGoal, and the…
Pieter
  • 13
  • 3
1
vote
1 answer

np.argmax on multidimensional arrays, keeping some indexes fixed

I have a collection of 2D narrays, depending on two integer indexes, say p1 and p2, with each matrix of the same shape. Then I need to find, for each pair (p1,p2), the maximum value of the matrix and the indexes of these maxima. A trivial, albeit…
0
votes
0 answers

Torch argmax() returns different results for tensor on Mac MPS and CPU

Torch argmax() returns correct results for tensor on CPU, but incorrect on MPS. I have a matrix target_mixtures, where print(target_mixtures[0]) would give tensor([0.0010, 0.6827, 0.0010, 0.0261, 0.0010, 0.0010, 0.0010, 0.0010, 0.0010, 0.0010,…
0
votes
0 answers

Pytorch and GPU with M1 chip

I have been trying to use my GPU on my Mac with M1 but I am encountering some issues when computing the accuracy of a CNN model through the epochs. After looking more closely, it seems like the argmax() function seems to always return this value…
Yaya Ney
  • 11
  • 1
0
votes
1 answer

Looking to use output from argmax to select level in another array

I am attempting to use the ERA-Interim vegetation cover fraction to determine the dominant vegetation cover. Essentially, there are 4 variables: low vegetation cover fraction, high vegetation cover fraction, low vegetation type and high vegetation…
0
votes
0 answers

Can't visualize my predicted masks for multi-class semantic segmentation

I'm trying to perform a 2D multi-class semantic segmentation on ACDC dataset which contains .nifti images: dataset link The original shape of the masks is (img_heght, img_wdth, img_dpth), so I stored the ground truth slices in np array format in the…
0
votes
1 answer

Vectorized version of argmax across 2D heatmaps

Input: C=17,H,W numpy array of 17 (C=Channels) body-joint HxW heatmaps. Desired output: Array of C=17 pairs of (Y,X) that specify the coordinates within H and W with the maximum value per each channel. I would like to use fully vectorized solution…
0
votes
0 answers

Forever running while loop in Reinforcement Learning agent evaluation

#Evaluating agents performance total_epochs, total_penalties = 0, 0 episodes = 1 for _ in range(episodes): state = env.reset() epochs, penalties, reward = 0 ,0 ,0 done = False while not done: state, reward, done, info =…
0
votes
1 answer

error using np.argmax when applying keepdims

I am running my Python code and recieving this error on keepdims: enter image description here This is the code: enter image description here It worked fine to run this command on my computer a few days ago but I have ran other codes etc after that…