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

Is there a way to filter out a frequency?

np.argmax function returns the highest frequency value and I want to take that value out and then see what the second highest value is. import wave import struct import matplotlib.pyplot as plt import numpy as np There is some code here but that…
thiccdan69
  • 11
  • 3
0
votes
2 answers

Argmax in a Keras multiclassifier ANN

I am trying to code a 5 class classifier ANN, and this code return this error: classifier = Sequential() classifier.add(Dense(units=10, input_dim=14, kernel_initializer='uniform', activation='relu')) …
0
votes
2 answers

Does np.argmax return the first maximal?

Does np.argmax return the index of the first maximal element always? Let a = np.array([1, 3, -7, ...]) be a 1D-array with several maximal elements, say at indices 10, 20 and 30. Numpy seems to return systematically 10 instead of 20 or 30, but I…
Carlos Pinzón
  • 1,286
  • 2
  • 15
  • 24
0
votes
0 answers

Python numpy np.argmax() using user specific range/axis

I have an array named fft with the length of length (800) and want to get the np.argmax(fft) and get as expected the maximum at position result (420). The data of the fft is from -pi/2 to pi/2 (-90° to 90°). So the position of the maximum is…
Dominik
  • 35
  • 5
0
votes
1 answer

How do I get the results from argmax of [0., 1e-8]?

When I ran below code, I got x=1, y=0 a = np.array([0., 1e-8]).astype('float32') x = a.argmax() y = (a+1).argmax() I already know floating point expression. But, I don't know why I can get x=1, y=0. I think that overflow or underflow can be…
douner
  • 21
  • 4
0
votes
0 answers

How do I get the Index of the max value in a column so I can get a value from a different column but same row?

The output of the panda's data frame: Date Time Hi Lo Open Close Volume 0 2021-12-10 4:00 174.80 174.56 174.73 174.8 953 1 2021-12-10 4:01 174.78 174.78 174.78 174.78 100 2 2021-12-10 4:02 …
0
votes
1 answer

How to find argmax/argmin in only selected indices of a Pytorch tensor

I have a distance tensor tensor([ 5, 10, 2, 3, 4], device='cuda:0') And a indices tensor tensor([ 0, 2, 3], device='cuda:0') I want to find argmax of the distance tensor but only on the subset of indices specified by the indices tensor. In…
Vojtooo
  • 103
  • 2
  • 6
0
votes
1 answer

Avoid segfault from `struct S as[] = {{NULL}};` with `struct S { const char *array[ARG_MAX]; };`?

On Apple clang version 12.0.5 (clang-1205.0.22.11) with gcc -ansi the following produces a segfault: #include #define ARG_MAX 1024 * 1024 struct S { const char *array[ARG_MAX]; }; int main(void) { struct S as[] = {{NULL}}; …
Samuel Marks
  • 1,611
  • 1
  • 20
  • 25
0
votes
1 answer

SQL groupby argmax

Let there be a table such as this: group ID member ID value 0 1 2 0 3 3 0 2 5 1 4 0 1 2 1 2 16 0 2 21 7 2 32 4 2 14 6 3 1 2 ... ... ... The table has three columns, a group ID, which uniquely indentifies a certain…
Captain Trojan
  • 2,800
  • 1
  • 11
  • 28
0
votes
2 answers

KeyError when trying to access column of a Pandas DataFrame

This is the first time I used stackoverflow so please forgive me if my question doesn't not follow proper conventions. I'm trying to create a function to find the station with the maximum riders on the first day, then return the mean riders per day…
0
votes
0 answers

N argmax columns out of max values in M rows?

What is the best/shortest way to get the TWO columns of with max value after selecting the THREE max in every specified row [[0. , 0. , 0. ], [0.19, 0. , 0. ], [0. , 0.29, 0. ], [0.42, 0. , 0.13], [0.12, 0.12, 0.13], [0.13,…
sten
  • 7,028
  • 9
  • 41
  • 63
0
votes
0 answers

np.argmax values for a multidimensional array

I have an output from a classification task with 3D array of shape (total_n, n_samples, class) where total_n is the total number of samples available, n_samples is number of samples each total_n has and class is the total number of classes. For…
iamkk
  • 135
  • 1
  • 16
0
votes
0 answers

Optimization problem for an undefined function in R

Suppose we have an unknown function $f:\mathbb R^n \to \mathbb R$ and a dataset of m rows and (n+1) columns of function values for some argument values $(x_{1,m}, x_{2,m},...,x_{n,m}, y_m)$, where m = 1,...,1000 and $y_{m} = f(x_{1,m},…
0
votes
2 answers

List of the (row, col) of the n largest values in a numeric pandas DataFrame?

Given a Pandas DataFrame of numeric values how can one produce a list of the .loc cell locations that one can then use to then obtain the corresponding n largest values in the entire DataFame? For…
user3673
  • 665
  • 5
  • 21
0
votes
1 answer

c++ finding argmax of vector from specific indices

from here, i know that we can get the argmax of a `vector like this: vector v{ 3, 1, -14, 1, 5, 9 }; vector::iterator result = max_element(v.begin(), v.end()); int argmaxVal = distance(v.begin(), result); // argmaxVal = 5 because v[5] =…
leonardltk1
  • 257
  • 1
  • 4
  • 18