作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
例如,找到下图,它解释了一个简单的 2D 情况的问题。每个点的标签 (N) 和坐标 (x,y) 已知。我需要找到位于红圈内的所有点标签
我的实际问题是在 3D 中,并且点分布不均匀
此处附有包含 7.25 M 点坐标的示例输入文件 point file .
我尝试了以下代码
import numpy as np
C = [50,50,50]
R = 20
centroid = np.loadtxt('centroid') #chk the file attached
def dist(x,y): return sum([(xi-yi)**2 for xi, yi in zip(x,y)])
elabels=[i+1 for i in range(len(centroid)) if dist(C,centroid[i])<=R**2]
单次搜索大约需要 10 分钟。有什么建议可以让它更快吗?
谢谢,普里蒂维
最佳答案
使用 numpy
时,避免在数组上使用列表推导式。
您可以使用这样的矢量化表达式来完成计算
centre = np.array((50., 50., 50.))
points = np.loadtxt('data')
distances2= np.sum((points-centre)**2, axis=1)
points
是一个 N x 2
数组,points-centre
也是一个 N x 2
数组,(points-centre)**2
计算差值每个元素的平方,最终 np.sum(..., axis=1)
对差值的元素求和沿轴编号的平方差1、即跨列。
要过滤位置数组,您可以使用 bool 索引
close = points[distances2<max_dist**2]
关于python - 找到位于球形区域内的所有点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40306661/
我有数百个位置的列表,只想显示当前屏幕上这些位置的 MKPinAnnotation。屏幕从 2 英里半径内的用户当前位置开始。当然,用户可以滚动和缩放屏幕。现在,我等待 map 更新事件,然后循环遍历
我试过检查 CGRect: CGFloat imageX1 = imageView.frame.origin.x; CGFloat imageY1 = imageView.frame.origin
我是一名优秀的程序员,十分优秀!