我在x,y
平面有很多點,長度約爲10000,每個點(x,y)
的固有半徑爲r
。這個小數據集只是我整個數據集的一個小角落。我有一個感興趣的點(x1,y1)
,我想找到1點附近的(x1,y1)
附近的點,並符合(x,y)
和(x1,y1)
之間的距離小於r
的標準。我想返回這些優點的索引,而不是優點本身。高效找到切割鄰居並返回索引
import numpy as np
np.random.seed(2000)
x = 20.*np.random.rand(10000)
y = 20.*np.random.rand(10000)
r = 0.3*np.random.rand(10000)
x1 = 10. ### (x1,y1) is an interest point
y1 = 12.
def index_finder(x,y,r,x1,y1):
idx = (abs(x - x1) < 1.) & (abs(y - y1) < 1.) ### This cut will probably cut 90% of the data
x_temp = x[idx] ### but if I do like this, then I lose the track of the original index
y_temp = y[idx]
dis_square = (x_temp - x1)*(x_temp - x1) + (y_temp - y1)*(y_temp - y1)
idx1 = dis_square < r*r ### after this cut, there are only a few left
x_good = x_temp[idx1]
y_good = y_temp[idx1]
在此功能,我可以找到好點左右(x1,y1)
,但那些好點的不是指數。但是,我需要ORIGINAL索引,因爲原始索引用於提取與座標(x,y)
相關的其他數據。正如我所提到的,樣本數據集只是我整個數據集的一個小角落,我將爲整個數據集調用上述函數大約1,000,000次,因此上述index_finder
函數的效率也是一個考慮因素。
對此類任務有何想法?
如何爲所有這些點使用index_finder?你是在循環中使用它還是就像那樣? – Divakar
我將在循環中使用這個函數因爲我有很多這樣的感興趣的點,比如'(x1,y1)'。這個函數本身可以避免任何循環。而這個數據集只有我整個數據集的1/1000。 –