Skip to content
Advertisement

How to find the maximum x value of a function?

I need to find the maximum x value associated to the maximum y value of the following function that I plot using Python matplotlib module:

JavaScript

Hence, the trend is this one:

plot

If I use the max() function in such way:

JavaScript

It prints only the maximum y value (that in this case is equal to 0.8306243772229114). How can I do to have also the maximum x value ?

Advertisement

Answer

If x is an np.array and you want to find the x associated with the maximum y, you can use np.argmax.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement