我在一个星团上做光圈测光,为了更容易检测到背景信号,我只想看比n像素(在我的例子中n=16)更远的恒星。 我有两个数组,xs和ys,它们的x和y值是所有恒星的坐标: 使用np.哪里我应该找到所有恒星的指数,其中到所有其他恒星的距离是>;=n
到目前为止,我的方法是一个for循环
import numpy as np
# Lists of coordinates w. values between 0 and 2000 for 5000 stars
xs = np.random.rand(5000)*2000
ys = np.random.rand(5000)*2000
# for-loop, wherein the np.where statement in question is situated
n = 16
for i in range(len(xs)):
index = np.where( np.sqrt( pow(xs[i] - xs,2) + pow(ys[i] - ys,2)) >= n)
由于恒星聚在一起非常紧密,我预计数据会严重减少,尽管即使我尝试n=1000,我仍然有大约4000个数据点
只使用
numpy
(和部分答案here)使用
scipy.spatial.pdist
使用KDTree实现最大速度:
您可以使用
np.subtract.outer
来创建成对比较。然后检查每一行的距离是否正好有一项小于16(这是与特定开始本身的比较):相关问题 更多 >
编程相关推荐