In [209]: vectorList = [(0, 10), (4, 8), (14, 14), (16, 19), (35, 16), (39,50)]
In [210]: vectorList
Out[210]: [(0, 10), (4, 8), (14, 14), (16, 19), (35, 16), (39, 50)]
Я добавил точку, сделав 3 возможных точки вставки.
In [212]: np.diff(vectorList, axis=0)
Out[212]:
array([[ 4, -2],
[10, 6],
[ 2, 5],
[19, -3],
[ 4, 34]])
In [213]: np.sum(np.diff(vectorList, axis=0)**2,1)
Out[213]: array([ 20, 136, 29, 370, 1172])
расстояния:
In [214]: np.sqrt(np.sum(np.diff(vectorList, axis=0)**2,1))
Out[214]: array([ 4.47213595, 11.66190379, 5.38516481, 19.23538406, 34.23448554])
Средние значения:
In [216]: arr = np.array(vectorList)
In [217]: arr
Out[217]:
array([[ 0, 10],
[ 4, 8],
[14, 14],
[16, 19],
[35, 16],
[39, 50]])
In [218]: (arr[:-1]+arr[1:])/2
Out[218]:
array([[ 2. , 9. ],
[ 9. , 11. ],
[15. , 16.5],
[25.5, 17.5],
[37. , 33. ]])
Iможет сделать нечто подобное без diff
:
d = np.sqrt(np.sum((arr[1:]-arr[:-1])**2,1))
Скачки, которые превышают порог:
In [224]: idx = np.nonzero(d>10)
In [225]: idx
Out[225]: (array([1, 3, 4]),)
In [227]: _218[idx] # the mean values to insert
Out[227]:
array([[ 9. , 11. ],
[25.5, 17.5],
[37. , 33. ]])
Используйте np.insert
для вставки всех значений.
In [232]: np.insert(arr.astype(float), idx[0]+1, _227, axis=0)
Out[232]:
array([[ 0. , 10. ],
[ 4. , 8. ],
[ 9. , 11. ],
[14. , 14. ],
[16. , 19. ],
[25.5, 17.5],
[35. , 16. ],
[37. , 33. ],
[39. , 50. ]])