Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8752803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:18:21+00:00 2026-06-13T13:18:21+00:00

scipy.spatial.distance.pdist returns a condensed distance matrix. From the documentation : Returns a condensed distance

  • 0

scipy.spatial.distance.pdist returns a condensed distance matrix. From the documentation:

Returns a condensed distance matrix Y. For each and (where ), the metric dist(u=X[i], v=X[j]) is computed and stored in entry ij.

I thought ij meant i*j. But I think I might be wrong. Consider

X = array([[1,2], [1,2], [3,4]])
dist_matrix = pdist(X)

then the documentation says that dist(X[0], X[2]) should be dist_matrix[0*2]. However, dist_matrix[0*2] is 0 — not 2.8 as it should be.

What’s the formula I should use to access the similarity of a two vectors, given i and j?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:18:22+00:00Added an answer on June 13, 2026 at 1:18 pm

    You can look at it this way: Suppose x is m by n. The possible pairs of m rows, chosen two at a time, is itertools.combinations(range(m), 2), e.g, for m=3:

    >>> import itertools
    >>> list(combinations(range(3),2))
    [(0, 1), (0, 2), (1, 2)]
    

    So if d = pdist(x), the kth tuple in combinations(range(m), 2)) gives the indices of the rows of x associated with d[k].

    Example:

    >>> x = array([[0,10],[10,10],[20,20]])
    >>> pdist(x)
    array([ 10.        ,  22.36067977,  14.14213562])
    

    The first element is dist(x[0], x[1]), the second is dist(x[0], x[2]) and the third is dist(x[1], x[2]).

    Or you can view it as the elements in the upper triangular part of the square distance matrix, strung together into a 1D array.

    E.g.

    >>> squareform(pdist(x)) 
    array([[  0.   ,  10.   ,  22.361],
           [ 10.   ,   0.   ,  14.142],
           [ 22.361,  14.142,   0.   ]])
    
    >>> y = array([[0,10],[10,10],[20,20],[10,0]])
    >>> squareform(pdist(y)) 
    array([[  0.   ,  10.   ,  22.361,  14.142],
           [ 10.   ,   0.   ,  14.142,  10.   ],
           [ 22.361,  14.142,   0.   ,  22.361],
           [ 14.142,  10.   ,  22.361,   0.   ]])
    >>> pdist(y)
    array([ 10.   ,  22.361,  14.142,  14.142,  10.   ,  22.361])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Several SciPy functions are documented as taking a condensed distance matrix as returned by
I'm using scipy.linalg to solve a matrix equation A*x = b The following code
I am using Scipy to construct a large, sparse (250k X 250k) co-occurrence matrix
Given a sparse matrix R of type scipy.sparse.coo_matrix of shape 1.000.000 x 70.000 I
I have a pointlist=[p1,p2,p3...] where p1 = [x1,y1],p2=[x2,y2] ... I want to use scipy.spatial.Delaunay
I am using Numpy/Scipy to invert a 20k matrix, it's slow. I tried: (1)
I have been using the scipy.stats.invgamma.rvs function to randomly select values from an inverse
I'm using dendrogram from scipy to plot hierarchical clustering using matplotlib as follows: mat
SciPy's documentation on LeastSq is here . It states that ier is An integer
With this code: import scipy from scipy import * x = r_[1:15] print x

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.