-4

I'm looking for the max value of two arrays, and I tried to get the max of each and add to another 'np.array'. However, I got 1.

maximums = [x_train.argmax(), x_test.argmax()]
print(maximums)
maximums = np.array(maximums)
print(maximums)
maximum = maximums.argmax()
print(maximum)

I expected the value of maximum to be 577, but it is 1.

[417, 577]
[417 577]
1

Where is the error, or why I don't get what I wanted?

EDITED: I found a function that makes what I wanted, and it is ´numpy.amax()´ https://thispointer.com/find-max-value-its-index-in-numpy-array-numpy-amax/

AMGMNPLK
  • 1,974
  • 3
  • 11
  • 22
  • `argmax` returns the index of the maximum value. Ref: https://docs.scipy.org/doc/numpy/reference/generated/numpy.argmax.html – amanb Jun 25 '19 at 10:15
  • "Returns the indices of the maximum values along an axis." See the docs: https://docs.scipy.org/doc/numpy/reference/generated/numpy.argmax.html – DeepSpace Jun 25 '19 at 10:16

3 Answers3

1

np.argmax returns the index for the maximum value. In this case, the index for maximum value 577 is 1. Offcial docs reference: https://docs.scipy.org/doc/numpy/reference/generated/numpy.argmax.html

To illustrate with an example, np.argmax is equivalent to getting the index for the maximum value in a list:

In [82]: import numpy as np

In [83]: vals = [477,577]

In [84]: max(vals)
Out[84]: 577

In [86]: vals.index(max(vals))
Out[86]: 1

In [87]: max_index = vals.index(max(vals))

In [88]: np.argmax(vals)
Out[88]: 1

In [89]: np.argmax(vals) == max_index
Out[89]: True
amanb
  • 5,276
  • 3
  • 19
  • 38
0

argmax returns the indices of the maximum values along an axis." Docs: docs.scipy.org/doc/numpy/reference/generated/numpy.argmax.html

zishan ahmed
  • 101
  • 1
  • 9
0

argmax gives you the index of the max value in the list, so you probably want to do something like:

j,w = x_train.argmax(), x_test.argmax()
maximums = [x_train[j], x_test[w]]

max_v = max(maximums)
print(max_v)
alec_djinn
  • 10,104
  • 8
  • 46
  • 71