How should I find the x_value corresponding to the max or min y_value of a parabola? (in Python)

Viewed 150

I've been tying to use np.where to find the x value that corresponds to the maximum y value of a parabola, here is what I did :

import numpy as np
x = np.arange(-10,10,step=1)
y = x**2+2*x
x = np.where(y=max)
print(x)

This clearly doesn't work

1 Answers

You can simply use argmin

import numpy as np
x = np.arange(-10,10,step=1)
y = x**2+2*x
idx = np.argmin(y)
print(x[idx])
Related