NearestFunction
更多信息
- NearestFunction 工作方式与 Function 相似.
- NearestFunction 由 Nearest[data] 生成.
- NearestFunction[…][x] 给出与特定元素 x 最接近的元素.
- NearestFunction[…][{x1,x2,…}] 给出与每个 xi 最接近的元素的列表.
- NearestFunction[…][x,n] 给出 n 个最接近的元素.
- NearestFunction[…][x,{n,r}] 最多给出 n 个距离 x 半径为 r 范围内最近的元素.
- NearestFunction[…][x,{All,r}] 给出距离 x 半径为 r 范围内的所有元素.
范例
打开所有单元 关闭所有单元基本范例 (1)
创建一个 NearestFunction:
nf = Nearest[{1, 3, 6, 10}]nf[5]使用 Map 应用于多个元素:
nf /@ {1, 2, 3, 4, 5, 6}nf[{1, 2, 3, 4, 5, 6}]范围 (3)
nf = Nearest[{1, 3, 6, 10}]nf[5, 3]nf = Nearest[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}]nf[5, {All, 2}]nf[5, {3, 2}]当 NearestFunction 直接用于多个点时,会尽量用并行线程计算结果:
data = RandomReal[1, {10 ^ 5, 2}];
nf = Nearest[data];
test = RandomReal[1, {10 ^ 6, 2}];AbsoluteTiming[nf[test];]当 NearestFunction 分别应用于各点,串行计算结果:
AbsoluteTiming[Map[nf, test];]相关指南
-
▪
- 计算几何
文本
Wolfram Research (2007),NearestFunction,Wolfram 语言函数,https://reference.wolfram.com/language/ref/NearestFunction.html.
CMS
Wolfram 语言. 2007. "NearestFunction." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/NearestFunction.html.
APA
Wolfram 语言. (2007). NearestFunction. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/NearestFunction.html 年
BibTeX
@misc{reference.wolfram_2026_nearestfunction, author="Wolfram Research", title="{NearestFunction}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/NearestFunction.html}", note=[Accessed: 31-October-2026]}
BibLaTeX
@online{reference.wolfram_2026_nearestfunction, organization={Wolfram Research}, title={NearestFunction}, year={2007}, url={https://reference.wolfram.com/language/ref/NearestFunction.html}, note=[Accessed: 31-October-2026]}