我有一个向量的 RDD 集合,其中每个向量表示一个点x
和y
坐标。例如,文件如下:
1.1 1.2
6.1 4.8
0.1 0.1
9.0 9.0
9.1 9.1
0.4 2.1
我正在阅读它:
def parseVector(line: String): Vector[Double] = {
DenseVector(line.split(' ')).map(_.toDouble)
}
val lines = sc.textFile(inputFile)
val points = lines.map(parseVector).cache()
另外,我有一个 epsilon:
val eps = 2.0
对于每个点,我想找到它在 epsilon 距离内的邻居。我愿意:
points.foreach(point =>
// squaredDistance(point, ?) what should I write here?
)
如何循环所有点并为每个点找到它的邻居?可能使用map
函数?