0

How do I find the intersection of two curves given by arrays y1 and y2, having the same x values? This is my current code:

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)

I'm getting an error in bisect:

...
  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
Dev-iL
  • 23,742
  • 7
  • 57
  • 99
learn_python
  • 17
  • 1
  • 4
  • Have you tried using numpy's `intersect1d()` method? – Rahul Bohare Jul 03 '18 at 10:03
  • What is the expected output in your example? When talking about the intersection of datasets, it usually means **common elements**. What you want to know is the intersection of **curves**, which is related but not the same thing. Please also include all imports to make the example runnable. – Dev-iL Jul 03 '18 at 16:05
  • See https://stackoverflow.com/questions/50437865/finding-the-interpolated-intersection-between-two-arrays-in-python-numpy-scipy – Warren Weckesser Jul 03 '18 at 17:52
  • 1
    Possible duplicate of [finding the interpolated intersection between two arrays in Python/Numpy/Scipy](https://stackoverflow.com/questions/50437865/finding-the-interpolated-intersection-between-two-arrays-in-python-numpy-scipy) – Dev-iL Jul 04 '18 at 08:18

0 Answers0