阈值距离后如何获取新的点列表?

时间:2019-04-12 10:27:39

标签: python distance threshold

我有一个带有坐标的数组。我计算所有点之间的距离。现在,我只想显示距离超过某个阈值的坐标。如何在python中执行此操作?

import numpy as np
import scipy
import matplotlib.pylab as plt

dx = np.array([b-a for a,b in combinations (x,2)])
dy = np.array([b-a for a,b in combinations (y,2)])
all_distances = scipy.stats.pdist( np.array(list(zip(x,y))) )
all_distances

df3=all_distances[~(all_distances<=35)]
df4=all_distances[~(all_distances<=40)]
df5=all_distances[~(all_distances<=45)]

fig, ax = plt.subplots()
plt.scatter(df3)
plt.ylabel('dy')
plt.xlabel('dx')
plt.show()

下面您将看到所有距离的点,但是现在我想要一个散点图,该点的阈值超过35

scatterplot

1 个答案:

答案 0 :(得分:0)

可能您正在寻找类似的东西

import numpy as np
from scipy.spatial.distance import pdist

combinations = np.array([(1,2), (3,4), (5,8), (10,12)])

all_distances = pdist( np.array(combinations))
print(all_distances)
print(all_distances[all_distances>3])

您可以对其他数组执行相同的操作,因此类似plt.scatter(dx[all_distances>35], dy[all_distances>35])的问题可以解决您的问题。