I wanted to have the intersections of two lines using numpy. The link that has introduced to me says how to reach the intersections but I got new error of
TypeError: only integer scalar arrays can be converted to a scalar index
The corrected code based on my dataset is below:
import numpy as np
import matplotlib.pyplot as plt
with open('configuration_300.out', 'r') as f:
lines = f.readlines()
x_1 = [float(line.split()[0]) for line in lines]
y_1 = [float(line.split()[1]) for line in lines]
g = [x_1, y_1]
## size of x_1 and y_1 is 1696
x_2 = np.zeros(1696)
y_2 = np.ones(1696)
h = [x_2,y_2]
def find_roots(g,h):
s = np.abs(np.diff(np.sign(h))).astype(float)
return g[:-1][s] + np.diff(g)[s]/(np.abs(h[1:][s]/g[:-1][s])+1)
z = find_roots(g,h)
import matplotlib.pyplot as plt
plt.plot(g,h)
plt.plot((z, np.zeros(len(z))), marker="o", ls="", ms=4)
plt.show()
After running I got the error which was aforementioned
All helps will be appreciated