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

How to get the index of maximum values along 2d in a 4d numpy array

Imagine you have a 3d array like e.g. A = np.array([[[1,2], [2,3] ], [[3,4], [1,2]], [[2,3], [3,4]]]) A.shape (3, 2, 2) array([[[1, 2], [2, 3]], [[3, 4], [1, 2]], [[2, 3], [3, 4]]]) Now, if I want to get…
nicrie
  • 199
  • 7
2
votes
1 answer

numpy argmax with groupby

Suppose I have labels to cluster data into several groups. Now I want to find the indices of the maximum w.r.t the original array for each cluster. For example: import numpy as np labels = np.array([1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0]) y =…
Osman Mamun
  • 2,864
  • 1
  • 16
  • 22
2
votes
2 answers

How to detect a tie in a numpy array when using argmax

If I have an array like below, how can I detect that there is a tie of at least 3 or more values when using np.argmax()? examp = np.array([[4, 0, 1, 4, 4], [5, 5, 1, 5, 5], [1, 2, 2, 4, 1], [4,…
Knovolt
  • 95
  • 8
2
votes
3 answers

Convert one-hot encoded dimension into the index of position of 1

I have a tensor of three dimensions [batch_size, sequence_length, number_of_tokens]. The last dimension is one-hot encoded. I want to receive a tensor of two dimensions, where sequence_length consists of the index position of '1' of the…
julliet
  • 147
  • 10
2
votes
0 answers

how to use torch.argmax and get only index value

Using torch==1.7.1 MRE: lst = [torch.rand(4).reshape(1,-1) for _ in range(5)] for each tensor, I want to get index of largest value. max_indexes = [torch.argmax(tensor) for tensor in lst] which outputting [tensor(0), tensor(0), tensor(2),…
haneulkim
  • 4,406
  • 9
  • 38
  • 80
2
votes
1 answer

In numpy, what is the efficient way to find the maximum values and their indices of a 3D ndarray across two axis?

How to find the correlation-peak values and coordinates of a set of 2D cross-correlation functions? Given an 3D ndarray that contains a set of 2D cross-correlation functions. What is the efficient way to find the maximum(peak) values and their…
L. Marval
  • 25
  • 4
2
votes
3 answers

Why is a new axis created, when only the first element is needed?

First of all, sorry for the vague title As I was interested in learning more about TensorFlow and Image segmentation, I was following their tutorial (https://www.tensorflow.org/tutorials/images/segmentation). However, I noticed something that I…
Marquiche
  • 23
  • 2
2
votes
1 answer

Can't access index of a list for maximum value with argmax

I am working on a Naïve Bayes Classifier and I got this list of arrays as the log predictions: predict = [array([-45.73329593, -47.23015876]), array([-56.83024746, -59.20630121]), array([-53.17297542, -55.19852072]), array([-35.67031864,…
Guillermina
  • 3,127
  • 3
  • 15
  • 24
2
votes
0 answers

c++ argmax of function(vector)

I have a vector v{1, 2, 3} I have a function: int square(int x){return x*x;} My question is: How do properly I find the argmax (in v) of square(v) ? In this case 9 is bigger than 4 and 1. Hence result should give 3. I could play with indices of…
2
votes
3 answers

Numpy arrays: row/column wise argmax with random ties

Here is what I am trying to do with Numpy in Python 2.7. Suppose I have an array a defined by the following: a = np.array([[1,3,3],[4,5,6],[7,8,1]]) I can do a.argmax(0) or a.argmax(1) to get the row/column wise argmax: a.argmax(0) Out[329]:…
blipblop
  • 155
  • 1
  • 12
2
votes
1 answer

MATLAB equivalent to Python argmax with array of user defined objects

I have an array as shown here. Here Bandit is a class that I created. bandits = [Bandit(m1),Bandit(m2),Bandit(m3)]; Now, I want to do the following. Following is Python code which immediately gives me the maxarg of the value of the mean of each of…
2
votes
1 answer

Python - argmax on a histogram

I'm trying to find peaks on the left and right halves of the image (basically this is a binary image of a road with left and right lanes). For some reason, the left argmax is giving a value to the right of midpoint, and right is giving beyond the…
Ravi
  • 561
  • 2
  • 7
  • 19
2
votes
0 answers

Keras model.predict - argmax always outputs 0 (seq2seq model)

I am working with the spelling bees code and applying it to a similar seq2seq task. I am struggling with the predition and the output of the argmax function. For some reason the output of the argmax returns only 0 for any case. I have changed a lot…
2
votes
1 answer

Python: how to interpret the outcome of np.argmax()?

The documentation on np.argmax() says that it Returns the indices of the maximum values along an axis. The examples given are straightforward: In[1]: a = np.arange(6).reshape(2,3) In[2]: a Out[2]: array([[0, 1, 2], [3, 4, 5]]) In[3]:…
FaCoffee
  • 7,609
  • 28
  • 99
  • 174
2
votes
2 answers

get the argmax from an array and save it - python

I have an array like the one below. How can I take the argmax from this array and save it as a dataframe. array ([[ 4.33578761e-03, 1.11002535e-01, 1.18002132e-01, 2.23158062e-01, 3.57010156e-01, 9.33912754e-01], [ …
Reese Fitzmaurice
  • 307
  • 1
  • 2
  • 8