Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
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:
Find the 3 elements nearest to 20:
Find which element is nearest to {2, 3} in 2D:
Find "nearest" strings:
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]=
Create a Voronoi diagram:
Use higher resolution:
Use a 1-norm ("taxicab distance"):
Highlight the 200 random points closest to the origin:
Use the "taxicab" metric:
Create a nearest function from all the words in a dictionary:
Look up words closest to a given word:
Go further:
Find the outputs from running a sequence of elementary cellular automata:
Generate a complete list of outputs from all 256 elementary cellular automata:
Find which rules give outputs nearest the specified sequences:
Find successive nearest words in a dictionary:
New in 6
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team