I'm using NumPy to find intersections on a graph, but isClose
returns multiple values per intersection
So, I'm going to try to find their averages. But first, I want to isolate the similar values. This is also a useful skill I feel.
I have a list of the x values for the intersection called idx
that looks like this
[-8.67735471 -8.63727455 -8.59719439 -5.5511022 -5.51102204 -5.47094188
-5.43086172 -2.4248497 -2.38476954 -2.34468938 -2.30460922 0.74148297
0.78156313 0.82164329 3.86773547 3.90781563 3.94789579 3.98797595
7.03406814 7.0741483 7.11422846]
and I want to separate it out into lists each comprised of the similar numbers.
this is what I have so far:
n = 0
for i in range(len(idx)):
try:
if (idx[n]-idx[n-1])<0.5:
sdx.append(idx[n-1])
else:
print(sdx)
sdx = []
except:
sdx.append(idx[n-1])
n = n+1
It works for the most part but it forgets some numbers:
[-8.6773547094188377, -8.6372745490981959]
[-5.5511022044088181, -5.5110220440881763, -5.4709418837675354]
[-2.4248496993987976, -2.3847695390781567, -2.3446893787575149]
[0.7414829659318638, 0.78156312625250379]
[3.8677354709418825, 3.9078156312625243, 3.9478957915831661]
Theres probably a more efficient way to do this, does anyone know of one?