我有这样的 Python 代码
import numpy as np
import matplotlib.pyplot as plt
import math
from scipy import optimize as opt
def func1(x):
f1 = math.exp(x-2)+x**3-x
return f1
solv1_bisect = opt.bisect(func1, -1.5, 1.5)
x1 = np.linspace(-1.5,1.5)
y1 = func1(x1)
plt.plot(x1,y1,'r-')
plt.grid()
print('solv1_bisect = ', solv1_bisect)
我收到了错误消息,例如
TypeError: only length-1 arrays can be converted to Python scalars
请帮我解决,谢谢!