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
2
votes
1 answer

One-hot representation of a matrix in numpy

What is the easiest/smartest way of going from a matrix of values to one hot representation of the same thing in 3d tensor? For example if the matrix is the index after argmax in a tensor like: indices=numpy.argmax(mytensor,axis=2) Where tensor is…
Amir Zadeh
  • 3,481
  • 2
  • 26
  • 47
2
votes
1 answer

Python- obtain maximum value in an interval

I have a .CSV file (a list) that contains 43142 rows and 2 columns. When plotting the list's values x vs y: import numpy as np import matplotlib.pyplot as plt filename=np.genfromtxt(list.CSV,delimiter=',') …
2
votes
2 answers

Splunk argmax: get field value corresponding to max value of another field

Let's say on Splunk, I have a table with the fields 'month', 'year', and 'count'. I want the month corresponding to the max count for each year. So, the resulting table should only have one month per year. I've tried using the stats and chart max…
Andrew Chen
  • 373
  • 1
  • 7
  • 16
2
votes
1 answer

Numpy.argmax() on certain axis in 2D matrix

I'm currently working on creating a ranking algorithm to rank relationships between students. In my NxN matrix F: F[i, j] refers to the relationship between student i and student j. The higher the value, the stronger the relationship. My…
Rob.Churchill
  • 35
  • 1
  • 5
2
votes
2 answers

What is the pythonic way to calculate argmax?

If i have a list and a function to calculate score, I could calculate argmax as such: maxscore = 0; argmax = None x = [3.49, 0.122, 293, 0.98] # Imagine a LARGE list. for i in x: # Maybe there're some other func() to calculate score # For…
alvas
  • 115,346
  • 109
  • 446
  • 738
1
vote
1 answer

numpy.argmax in C++ OpenCV

I am using OpenCV (4.6.0) DNN module to generate semantic segmentation of images and the output of the network is a cv::Mat with the size of (numberOfClasses x image_height x image_width) that contains the class probabilities for every pixel. I want…
1
vote
1 answer

kusto KQL summarize argmax() returns modified column names

I have a quite big table as input where two fields (Id, StartTsUtc) form a unique key. the TimeStamp shows several updates for this unique key Wanting to keep only the latest update for each (Id,StartTsUtc), I'm applying the argmax function |…
Kermit754
  • 343
  • 5
  • 14
1
vote
1 answer

Getting argmax indexes from one ndarray and use them to get values from another array

I am taking the argmax from one ndarray and I have to use it to get elements from another ndarray. An example usage of this is "get the weights of the tallest people". Where the heights are in one ndarray and the weights are in another. The code…
Vitaly Olegovitch
  • 3,509
  • 6
  • 33
  • 49
1
vote
1 answer

Return label of the column which has the maximum value if it is higher than a certain number

I have a pandas dataframe with 18 columns, the columns from 2:17 hold numerical values with labels 2-17. I want to add a new column ('category') to the dataframe to include the label of the column which holds the maximum value if that value is…
AHmDania
  • 13
  • 3
1
vote
1 answer

How to skip nan slices in xarray argmax() function?

I have a large multidimensional xarray data array. I am trying to apply xarray.argmax() to each column but am unable to since some of the "slices" are all-NaN. Here is a smaller, reproducible version of my problem: import xarray da =…
1
vote
2 answers

ValueError: attempt to get argmax of an empty sequence when trying to pull index of max value in columns

Try to get the index of the max value in column Hi column so I can get the value in the Time column NumPy/pandas is up to date The output of the panda's data frame: Date Time Hi Lo Open Close Volume 241 2021-12-10 …
1
vote
0 answers

How to solve the situation that all values are 0 after dimensionality reduction using pytorch.argmax?

As shown in the following code, after I put the input image into the model to obtain the output, I want to use argmax to reduce the dimensionality, but the results after argmax all become 0. What is the reason for this, should I use other methods…
1
vote
1 answer

Comparing array row-wise so as to generalize argmax function

Using Python, consider an array X containing 2d data: X = np.array([x0,y0], ..., [xn,yn]) and three 1d arrays Y_A, Y_B, Y_C of same length as X containing numbers. Finally consider 3 empty arrays A,B,C. How can I fill these empty arrays A,B,C…
Marion
  • 271
  • 3
  • 11
1
vote
0 answers

Find x-values of several peaks of a data set

in the following figure two data sets are plotted. The values of each data set are in the following form: PixelNo 0 821.0 1 943.0 2 806.0 3 753.0 4 834.0 ... 3586 932.0 3587 828.0 3588 786.0 3589 …
Karl
  • 59
  • 7
1
vote
2 answers

Create new 2d array of the argmax from two 2d np.arrays element-wise

Say I have, as an arbitrary example, two 2d numpy arrays, X and Y where X = np.array([[0,1,2,3], [4,5,6,7]]) Y = np.array([[1,2,3,4], [1,1,7,3]]) I want to create a new 2d numpy array, Z, that is the…
Zuckerbrenner
  • 323
  • 2
  • 15