Search for all pages containing Nearest
Mathematica > Data Manipulation > Numerical Data > Exploratory Data Analysis >
Mathematica > Data Manipulation > Statistics > Exploratory Data Analysis >
Mathematica > Mathematics and Algorithms > Statistics > Exploratory Data Analysis >

Nearest

Nearest[{elem1, elem2, ...}, x]
gives the list of elemi to which x is nearest.
Nearest[{elem1->v1, elem2->v2, ...}, x]
gives the vi corresponding to the elemi to which x is nearest.
Nearest[{elem1, elem2, ...}->{v1, v2, ...}, x]
gives the same result.
Nearest[{elem1, elem2, ...}->Automatic, x]
takes the vi to be successive integers i.
Nearest[data, x, n]
gives the n nearest elemi to x.
Nearest[data]
generates a NearestFunction[...] which can be applied repeatedly to different x.
  • If the elemi are vectors or matrices of numbers, Nearest by default in effect uses the metric Norm[#1-#2]&.
  • For strings, Nearest by default uses the edit distance metric.
  • The following option can be given:
DistanceFunctionAutomaticthe distance metric to use
  • When several elements are returned, the nearest ones are given first.
  • If several elements are at the same distance, they are returned in the order they appear in data.
Find the element nearest to 20:
In[1]:=
Click for copyable input
Out[1]=
Find the 3 elements nearest to 20:
In[2]:=
Click for copyable input
Out[2]=
 
Find which element is nearest to {2, 3} in 2D:
In[1]:=
Click for copyable input
Out[1]=
 
Find "nearest" strings:
In[1]:=
Click for copyable input
Out[1]=
New in 6
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team