Questions tagged [distance-matrix]

A distance matrix is a matrix containing the pairwise distances between the elements of a set. The "distance" may rely on the concept of metric.

The distance matrix for an N-elements set is a NxN matrix in which entry (i,j) contains the distance between items i and j.
The distance might be related to the concept of metric (e.g. Euclidean distance, Mahlanobis distance, and so on) but there are also non-metric distance matrices: an adjacency matrix is an example of such non-metric distance matrices.

174 questions
3
votes
1 answer

Not able to access value of variable derived from google distance matrix function

I am using Google distance matrix api to get the distance between two locations. I declared a variable globally. Changed this variable in function. But as per normal circumstances I should be able to access this changed value of variable after…
3
votes
1 answer

bootstrapping coefficients of multiple regression of distance matrices (MRM)

I want to estimate frequency distributions of MRM coefficients to generate a 95% CI. Below is the initial code: library(ecodist) dat=data.frame(matrix(rnorm(3*25),ncol=3)) names(dat)<-c('Pred','Var1','Var2') mod<-MRM(dist(Pred) ~ dist(Var1) + dist…
2
votes
2 answers

How can I efficiently plot a distance matrix using seaborn?

So I have a dataset of more ore less 11.000 records, with 4 features all them are discrete or continue. I perform clustering using K-means, then I add the column "cluster" to the dataframe using kmeans.labels_. Now I want to plot the distance matrix…
JayJona
  • 469
  • 1
  • 16
  • 41
2
votes
2 answers

How to efficiently iterate through rows in a large matrix with too many columns?

I'm working on document clustering where I first build a distance matrix from the tf-idf results. I use the below code to get my tf-idf matrix: from sklearn.feature_extraction.text import TfidfVectorizer vectorizer =…
Mahdi
  • 251
  • 2
  • 12
2
votes
0 answers

Get driving distance between multiple points - currently using open route service - but need a faster way similar to google distance matrix but free

I need assistance in a faster distance matrix tool for approximately 107000 source points and 220 destination points. I currently use Open route services on docker, it generates memory error if I run the whole thing, so I run it in a loop i.e.…
2
votes
1 answer

Vizualize distance matrix into graph

For the following distance matrix: ∞, 1, 2 ∞, ∞, 1 ∞, ∞, ∞ I would need to visualise the following graph: That's how it should look like I tried with the following code: import networkx as nx import numpy as np import string dt = [('len',…
LimetaPeta
  • 67
  • 5
2
votes
1 answer

How to calculate the distance between all atoms in a PDB file and create a distance matrix from that

I would like to calculate the distances between all atom in a pdb file and then create a distance matrix from the result of the PDB. I currently have all the x, y and z coordinates but I am struggling to to do this distance calculation for all…
2
votes
0 answers

can i use OR-tools for TSP with partial distance matrix (for a huge set of nodes)?

i'm trying to solve tsp with OR-tools for a problem of something like 80,000 nodes, the problem is, I need a huge distance matrix that takes to much memory ,so its infeasible and i don't get a solution. so: is there an option to work with partial…
2
votes
2 answers

Convert a distance matrix to a list of pairwise distances in Python

Assume the following distance matrix in python... 0 1 2 3 0 0 1 4 8 1 1 0 3 7 2 4 3 0 3 3 8 7 3 0 I would like to convert this distance matrix to a list of pairwise euclidean distances, as below... Obj1 Obj2 Dist 0 0 1 1 1 0 2 …
Ben
  • 123
  • 6
2
votes
1 answer

Julia: Broadcasting pairwise distance calculation across tensor of observations

I am trying to use the Distances package in Julia to perform a broadcasted computation of distance matrices. I understand how to calculate a single N x N distance matrix for some matrix X (with dimensions D x N), where each column X[:,i] stores a…
Conor
  • 691
  • 5
  • 14
2
votes
1 answer

Distance matrix api for Google

I am using Google Distance Matrix API. But I am unable to figure out the API cost, it has written on their website that "price per element". So, if I have two origins and 1000 destinations, then what will be my total API cost, and is the example…
2
votes
2 answers

Python: generate distance matrix for large number of locations

I want to generate a distance matrix 500X500 based on latitude and longitude of 500 locations, using Haversine formula. Here is the sample data "coordinate.csv" for 10…
belle
  • 109
  • 2
  • 11
2
votes
1 answer

Finding pairwise labels for the minimum value from a distance matrix dataframe

I have a scipy distance_matrix as a dataframe. How do I extract the minimum value (excluding 0.00) per row along with the associated (row,column) labels for that values from a dataframe? For example: The min for the first row would be…
Carl C
  • 135
  • 8
2
votes
0 answers

wasserstein distance for multiple histograms

I'm trying to calculate the distance matrix between histograms. I can only find the code for calculating the distance between 2 histograms and my data have more than 10. My data is a CSV file and histogram comes in columns that add up to 100. Which…
2
votes
1 answer

Create custom distance matrix function in R

I am tasked with creating a distance matrix function based on a custom defined distance measure. The distance measure is as follows: wabs_dist = function(u, v, w){ return( sum((abs(u-v))*w) ) } Where u and v are vectors and w is a weight. The…
Devee
  • 61
  • 9
1
2
3
11 12