Numpy 如何找到两条曲线的交点?

Numpy 如何找到两条曲线的交点?,numpy,scipy,2d,intersection,curves,Numpy,Scipy,2d,Intersection,Curves,如何找到由具有相同x值的数组y1和y2给出的两条曲线的交点?这是我当前的代码: import numpy as np import matplotlib.pyplot as plt from scipy import optimize fig = plt.figure() ax = fig.add_subplot(111) Ls = [2, 4] for L in range(len(Ls)): x = np.arange(10) y1 = np.array([2, 4, 6,

如何找到由具有相同x值的数组
y1
y2
给出的两条曲线的交点?这是我当前的代码:

import numpy as np
import matplotlib.pyplot as plt
from scipy import optimize

fig = plt.figure()
ax = fig.add_subplot(111)
Ls = [2, 4]
for L in range(len(Ls)):
    x = np.arange(10)
    y1 = np.array([2, 4, 6, 8, 10, 12, 14, 16, 18, 20])
    y2 = np.array([20, 18, 16, 14, 12, 10, 8, 6, 4, 2])
    ax.plot(x, y1, x, y2)
    ax.set_label("x")
    ax.set_label("y")

f = np.sign(y1 - y2)
optimize.bisect(f, 4, 6)
我在对分中得到一个错误:

...
  File "...\scipy\optimize\zeros.py", line 249, in bisect
    r = _zeros._bisect(f,a,b,xtol,rtol,maxiter,args,full_output,disp)
TypeError: 'numpy.ndarray' object is not callable

您是否尝试过使用numpy的
intersect1d()
方法?您的示例中预期的输出是什么?当谈到数据集的交集时,通常指的是公共元素。你想知道的是曲线的交点,它是相关的,但不是相同的东西。还请包括所有导入以使示例可运行。请参阅的可能副本