Products
  • Wolfram|One

    The definitive Wolfram Language and notebook experience

  • Mathematica

    The original technical computing environment

  • Wolfram Notebook Assistant + LLM Kit

    All-in-one AI assistance for your Wolfram experience

  • System Modeler
  • Wolfram Player
  • Finance Platform
  • Wolfram Engine
  • Enterprise Private Cloud
  • Application Server
  • Wolfram|Alpha Notebook Edition
  • Wolfram Cloud App
  • Wolfram Player App

More mobile apps

Core Technologies of Wolfram Products

  • Wolfram Language
  • Computable Data
  • Wolfram Notebooks
  • AI & Linguistic Understanding

Deployment Options

  • Wolfram Cloud
  • wolframscript
  • Wolfram Engine Community Edition
  • Wolfram LLM API
  • WSTPServer
  • Wolfram|Alpha APIs

From the Community

  • Function Repository
  • Community Paclet Repository
  • Example Repository
  • Neural Net Repository
  • Prompt Repository
  • Wolfram Demonstrations
  • Data Repository
  • Group & Organizational Licensing
  • All Products
Consulting & Solutions

We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

  • Data & Computational Intelligence
  • Model-Based Design
  • Algorithm Development
  • Wolfram|Alpha for Business
  • Blockchain Technology
  • Education Technology
  • Quantum Computation

WolframConsulting.com

Wolfram Solutions

  • Data Science
  • Artificial Intelligence
  • Biosciences
  • Healthcare Intelligence
  • Sustainable Energy
  • Control Systems
  • Enterprise Wolfram|Alpha
  • Blockchain Labs

More Wolfram Solutions

Wolfram Solutions For Education

  • Research Universities
  • Colleges & Teaching Universities
  • Junior & Community Colleges
  • High Schools
  • Educational Technology
  • Computer-Based Math

More Solutions for Education

  • Contact Us
Learning & Support

Get Started

  • Wolfram Language Introduction
  • Fast Intro for Programmers
  • Fast Intro for Math Students
  • Wolfram Language Documentation

More Learning

  • Highlighted Core Areas
  • Demonstrations
  • YouTube
  • Daily Study Groups
  • Wolfram Schools and Programs
  • Books

Grow Your Skills

  • Wolfram U

    Courses in computing, science, life and more

  • Community

    Learn, solve problems and share ideas.

  • Blog

    News, views and insights from Wolfram

  • Resources for

    Software Developers

Tech Support

  • Contact Us
  • Support FAQs
  • Support FAQs
  • Contact Us
Company
  • About Wolfram
  • Career Center
  • All Sites & Resources
  • Connect & Follow
  • Contact Us

Work with Us

  • Student Ambassador Initiative
  • Wolfram for Startups
  • Student Opportunities
  • Jobs Using Wolfram Language

Educational Programs for Adults

  • Summer School
  • Winter School

Educational Programs for Youth

  • Middle School Camp
  • High School Research Program
  • Computational Adventures

Read

  • Stephen Wolfram's Writings
  • Wolfram Blog
  • Wolfram Tech | Books
  • Wolfram Media
  • Complex Systems

Educational Resources

  • Wolfram MathWorld
  • Wolfram in STEM/STEAM
  • Wolfram Challenges
  • Wolfram Problem Generator

Wolfram Initiatives

  • Wolfram Science
  • Wolfram Foundation
  • History of Mathematics Project

Events

  • Stephen Wolfram Livestreams
  • Online & In-Person Events
  • Contact Us
  • Connect & Follow
Wolfram|Alpha
  • Your Account
  • User Portal
  • Wolfram Cloud
  • Products
    • Wolfram|One
    • Mathematica
    • Wolfram Notebook Assistant + LLM Kit
    • System Modeler
    • Wolfram Player
    • Finance Platform
    • Wolfram|Alpha Notebook Edition
    • Wolfram Engine
    • Enterprise Private Cloud
    • Application Server
    • Wolfram Cloud App
    • Wolfram Player App

    More mobile apps

    • Core Technologies
      • Wolfram Language
      • Computable Data
      • Wolfram Notebooks
      • AI & Linguistic Understanding
    • Deployment Options
      • Wolfram Cloud
      • wolframscript
      • Wolfram Engine Community Edition
      • Wolfram LLM API
      • WSTPServer
      • Wolfram|Alpha APIs
    • From the Community
      • Function Repository
      • Community Paclet Repository
      • Example Repository
      • Neural Net Repository
      • Prompt Repository
      • Wolfram Demonstrations
      • Data Repository
    • Group & Organizational Licensing
    • All Products
  • Consulting & Solutions

    We deliver solutions for the AI era—combining symbolic computation, data-driven insights and deep technical expertise

    WolframConsulting.com

    Wolfram Solutions

    • Data Science
    • Artificial Intelligence
    • Biosciences
    • Healthcare Intelligence
    • Sustainable Energy
    • Control Systems
    • Enterprise Wolfram|Alpha
    • Blockchain Labs

    More Wolfram Solutions

    Wolfram Solutions For Education

    • Research Universities
    • Colleges & Teaching Universities
    • Junior & Community Colleges
    • High Schools
    • Educational Technology
    • Computer-Based Math

    More Solutions for Education

    • Contact Us
  • Learning & Support

    Get Started

    • Wolfram Language Introduction
    • Fast Intro for Programmers
    • Fast Intro for Math Students
    • Wolfram Language Documentation

    Grow Your Skills

    • Wolfram U

      Courses in computing, science, life and more

    • Community

      Learn, solve problems and share ideas.

    • Blog

      News, views and insights from Wolfram

    • Resources for

      Software Developers
    • Tech Support
      • Contact Us
      • Support FAQs
    • More Learning
      • Highlighted Core Areas
      • Demonstrations
      • YouTube
      • Daily Study Groups
      • Wolfram Schools and Programs
      • Books
    • Support FAQs
    • Contact Us
  • Company
    • About Wolfram
    • Career Center
    • All Sites & Resources
    • Connect & Follow
    • Contact Us

    Work with Us

    • Student Ambassador Initiative
    • Wolfram for Startups
    • Student Opportunities
    • Jobs Using Wolfram Language

    Educational Programs for Adults

    • Summer School
    • Winter School

    Educational Programs for Youth

    • Middle School Camp
    • High School Research Program
    • Computational Adventures

    Read

    • Stephen Wolfram's Writings
    • Wolfram Blog
    • Wolfram Tech | Books
    • Wolfram Media
    • Complex Systems
    • Educational Resources
      • Wolfram MathWorld
      • Wolfram in STEM/STEAM
      • Wolfram Challenges
      • Wolfram Problem Generator
    • Wolfram Initiatives
      • Wolfram Science
      • Wolfram Foundation
      • History of Mathematics Project
    • Events
      • Stephen Wolfram Livestreams
      • Online & In-Person Events
    • Contact Us
    • Connect & Follow
  • Wolfram|Alpha
  • Wolfram Cloud
  • Your Account
  • User Portal
Wolfram Language & System Documentation Center
DistanceMatrix
  • See Also
    • Outer
    • NearestNeighborGraph
    • AdjacencyMatrix
    • GraphDistanceMatrix
    • Nearest
    • Norm
    • ClusterClassify
    • FindClusters
    • DistanceFunction
  • Related Guides
    • Distance and Similarity Measures
    • Operations on Vectors
    • Sequence Alignment & Comparison
    • Text Analysis
    • Natural Language Processing
    • See Also
      • Outer
      • NearestNeighborGraph
      • AdjacencyMatrix
      • GraphDistanceMatrix
      • Nearest
      • Norm
      • ClusterClassify
      • FindClusters
      • DistanceFunction
    • Related Guides
      • Distance and Similarity Measures
      • Operations on Vectors
      • Sequence Alignment & Comparison
      • Text Analysis
      • Natural Language Processing

DistanceMatrix[{u1,u2,…}]

gives the matrix of distances between each pair of elements ui, uj.

DistanceMatrix[{u1,u2,…},{v1,v2,…}]

gives the matrix of distances between each pair of elements ui, vj.

Details and Options
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Options  
DistanceFunction  
FeatureExtractor  
FeatureNames  
Show More Show More
FeatureTypes  
PerformanceGoal  
RandomSeeding  
WorkingPrecision  
Applications  
See Also
Related Guides
History
Cite this Page
BUILT-IN SYMBOL
  • See Also
    • Outer
    • NearestNeighborGraph
    • AdjacencyMatrix
    • GraphDistanceMatrix
    • Nearest
    • Norm
    • ClusterClassify
    • FindClusters
    • DistanceFunction
  • Related Guides
    • Distance and Similarity Measures
    • Operations on Vectors
    • Sequence Alignment & Comparison
    • Text Analysis
    • Natural Language Processing
    • See Also
      • Outer
      • NearestNeighborGraph
      • AdjacencyMatrix
      • GraphDistanceMatrix
      • Nearest
      • Norm
      • ClusterClassify
      • FindClusters
      • DistanceFunction
    • Related Guides
      • Distance and Similarity Measures
      • Operations on Vectors
      • Sequence Alignment & Comparison
      • Text Analysis
      • Natural Language Processing

DistanceMatrix

DistanceMatrix[{u1,u2,…}]

gives the matrix of distances between each pair of elements ui, uj.

DistanceMatrix[{u1,u2,…},{v1,v2,…}]

gives the matrix of distances between each pair of elements ui, vj.

Details and Options

  • DistanceMatrix works for a variety of data, including numerical, geospatial, textual, visual, dates and times, as well as combinations of these.
  • Each ui can be a single data element, a list of data elements or an association of data elements. In DistanceMatrix[data,…], data can also be a Dataset object.
  • The following options can be given:
  • DistanceFunction Automaticthe distance metric to use
    FeatureExtractor Identityhow to preprocess data
    FeatureNames Automaticfeature names to assign for data
    FeatureTypes Automaticfeature types to assume for data
    PerformanceGoal Automaticaspects of performance to try to optimize
    RandomSeeding 1234what seeding of pseudorandom generators should be done internally
    WorkingPrecision Automaticprecision to use for numerical data
  • The setting for DistanceFunction can be any distance or dissimilarity function or a function f defining a distance between two values.
  • By default, the following distance functions are used for different types of elements:
  • EuclideanDistancenumeric data
    ImageDistanceimages
    JaccardDissimilarityBoolean data
    EditDistancetext and nominal sequences
    Abs[DateDifference[#1,#2]]&dates and times
    ColorDistancecolors
    GeoDistancegeospatial data
    Boole[SameQ[#1,#2]]&nominal data
    HammingDistancenominal vector data
    WarpingDistancenumerical sequences
  • For images, colors or audio objects and a distance function f, DistanceFunction->f is passed to ImageDistance, ColorDistance or AudioDistance, respectively. »
  • All images are first conformed using ConformImages.
  • By default, when data elements are mixed-type vectors, distances are computed independently for each type and combined using Norm.
  • Possible settings for PerformanceGoal include:
  • "Speed"minimize computation time
    "Quality"maximize precision and accuracy
    Automaticautomatic tradeoff between speed and precision
  • Possible settings for RandomSeeding include:
  • Automaticautomatically reseed every time the function is called
    Inheriteduse externally seeded random numbers
    seeduse an explicit integer or strings as a seed

Examples

open all close all

Basic Examples  (3)

Compute a distance matrix from a list of integers:

Compute a distance matrix from two lists of integers:

Compute a distance matrix from real-valued numerical vectors:

Scope  (10)

Compute a distance matrix from images:

Compute a distance matrix from strings:

Compute a distance matrix from Boolean vectors:

Compute a distance matrix from a list of date objects:

Compute a distance matrix from geodetic positions:

Compute a distance matrix from nominal sequences:

Compute a distance matrix from numerical sequences:

Compute a distance matrix on nominal vectors:

Compute a distance matrix from mixed-type vectors:

Compute a distance matrix from a dataset formatted as a list of associations:

Compute the same distance matrix with a column-oriented dataset:

Data can also be given in a Dataset object:

Options  (9)

DistanceFunction  (3)

Compute a distance matrix from integer vectors using SquaredEuclideanDistance as a distance function:

Compute a distance matrix with the ManhattanDistance:

Use a color distance different from the default distance:

FeatureExtractor  (1)

Compute a distance matrix from images preprocessed by the feature extractor method "NumericVector":

FeatureNames  (1)

Use FeatureNames to name features, and refer to their names in further specifications:

FeatureTypes  (1)

Use FeatureTypes to enforce the interpretation of the first feature as nominal:

PerformanceGoal  (1)

Generate 2000 random numerical vectors of length 1000:

Compute their distance matrix and benchmark the operation:

Perform the same operation with PerformanceGoal set to "Speed":

Compare timing and accuracies of the previous results with a reference:

When PerformanceGoal"Speed", centering the data can increase the precision:

RandomSeeding  (1)

DistanceMatrix gives the same result when evaluated multiple times, even when randomness is involved.

Generate a pair of 20-dimensional vectors:

Compute its distance matrix several times using a feature extractor involving randomness:

Compare the results:

Use different values for the RandomSeeding option to compute the distance matrices:

Compare the results:

WorkingPrecision  (1)

Compute the distance matrix for 500 random numerical vectors of length 100 that have a precision of 30:

DistanceMatrix uses arbitrary-precision computation:

Using WorkingPrecisionMachinePrecision can speed up the computation:

But the results are not as precise:

When vectors are similar, changing the value of WorkingPrecision can lead to significantly different results:

Applications  (1)

Find the minimum distance between two sets of points:

See Also

Outer  NearestNeighborGraph  AdjacencyMatrix  GraphDistanceMatrix  Nearest  Norm  ClusterClassify  FindClusters  DistanceFunction

Function Repository: CayleyMengerMatrix  FindDistanceInstance  MultidimensionalScaling

Related Guides

    ▪
  • Distance and Similarity Measures
  • ▪
  • Operations on Vectors
  • ▪
  • Sequence Alignment & Comparison
  • ▪
  • Text Analysis
  • ▪
  • Natural Language Processing

History

Introduced in 2015 (10.3) | Updated in 2017 (11.1) ▪ 2017 (11.2)

Wolfram Research (2015), DistanceMatrix, Wolfram Language function, https://reference.wolfram.com/language/ref/DistanceMatrix.html (updated 2017).

Text

Wolfram Research (2015), DistanceMatrix, Wolfram Language function, https://reference.wolfram.com/language/ref/DistanceMatrix.html (updated 2017).

CMS

Wolfram Language. 2015. "DistanceMatrix." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2017. https://reference.wolfram.com/language/ref/DistanceMatrix.html.

APA

Wolfram Language. (2015). DistanceMatrix. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DistanceMatrix.html

BibTeX

@misc{reference.wolfram_2025_distancematrix, author="Wolfram Research", title="{DistanceMatrix}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/DistanceMatrix.html}", note=[Accessed: 01-December-2025]}

BibLaTeX

@online{reference.wolfram_2025_distancematrix, organization={Wolfram Research}, title={DistanceMatrix}, year={2017}, url={https://reference.wolfram.com/language/ref/DistanceMatrix.html}, note=[Accessed: 01-December-2025]}

Top
Introduction for Programmers
Introductory Book
Wolfram Function Repository | Wolfram Data Repository | Wolfram Data Drop | Wolfram Language Products
Top
  • Products
  • Wolfram|One
  • Mathematica
  • Notebook Assistant + LLM Kit
  • System Modeler

  • Wolfram|Alpha Notebook Edition
  • Wolfram|Alpha Pro
  • Mobile Apps

  • Wolfram Player
  • Wolfram Engine

  • Volume & Site Licensing
  • Server Deployment Options
  • Consulting
  • Wolfram Consulting
  • Repositories
  • Data Repository
  • Function Repository
  • Community Paclet Repository
  • Neural Net Repository
  • Prompt Repository

  • Wolfram Language Example Repository
  • Notebook Archive
  • Wolfram GitHub
  • Learning
  • Wolfram U
  • Wolfram Language Documentation
  • Webinars & Training
  • Educational Programs

  • Wolfram Language Introduction
  • Fast Introduction for Programmers
  • Fast Introduction for Math Students
  • Books

  • Wolfram Community
  • Wolfram Blog
  • Public Resources
  • Wolfram|Alpha
  • Wolfram Problem Generator
  • Wolfram Challenges

  • Computer-Based Math
  • Computational Thinking
  • Computational Adventures

  • Demonstrations Project
  • Wolfram Data Drop
  • MathWorld
  • Wolfram Science
  • Wolfram Media Publishing
  • Customer Resources
  • Store
  • Product Downloads
  • User Portal
  • Your Account
  • Organization Access

  • Support FAQ
  • Contact Support
  • Company
  • About Wolfram
  • Careers
  • Contact
  • Events
Wolfram Community Wolfram Blog
Legal & Privacy Policy
WolframAlpha.com | WolframCloud.com
© 2025 Wolfram
© 2025 Wolfram | Legal & Privacy Policy |
English