![](/img/trans.png)
[英]Removing points from list if distance between 2 points is below a certain threshold
[英]How to get new list of points after threshold distance?
我有一个带坐标的数组。 我计算所有点之间的距离。 现在我只想显示距离超过某个阈值的坐标。 我怎么能在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的散点图
愿你找到这样的东西
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])
可以解决你的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.