NearestFunction[data]
represents a function whose values give the elements closest to an element that is supplied.


NearestFunction
NearestFunction[data]
represents a function whose values give the elements closest to an element that is supplied.
Details

- NearestFunction works like Function.
- NearestFunction is generated by Nearest[data].
- NearestFunction[…][x] gives the element closest to a particular element x.
- NearestFunction[…][{x1,x2,…}] gives a list of the elements closest to each of the xi.
- NearestFunction[…][x,n] gives the n nearest elements.
- NearestFunction[…][x,{n,r}] gives the at most n nearest elements within radius r of x.
- NearestFunction[…][x,{All,r}] gives all elements within radius r of x.
Examples
open all close allBasic Examples (1)
Generate a NearestFunction:
Apply to several elements using Map:
Scope (3)
Give the elements within radius 2:
Give the at most 3 nearest elements within radius 2:
When NearestFunction is directly applied to multiple points, results are computed in parallel threads if possible:
When the NearestFunction is applied to the points separately, results are computed serially:
See Also
Tech Notes
Related Guides
History
Text
Wolfram Research (2007), NearestFunction, Wolfram Language function, https://reference.wolfram.com/language/ref/NearestFunction.html.
CMS
Wolfram Language. 2007. "NearestFunction." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NearestFunction.html.
APA
Wolfram Language. (2007). NearestFunction. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NearestFunction.html
BibTeX
@misc{reference.wolfram_2025_nearestfunction, author="Wolfram Research", title="{NearestFunction}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/NearestFunction.html}", note=[Accessed: 11-August-2025]}
BibLaTeX
@online{reference.wolfram_2025_nearestfunction, organization={Wolfram Research}, title={NearestFunction}, year={2007}, url={https://reference.wolfram.com/language/ref/NearestFunction.html}, note=[Accessed: 11-August-2025]}