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
1
vote
0 answers

Find indices of closest samples in distance matrix

import torch from torch.utils.data import DataLoader from torchvision import datasets, transforms myTransform = transforms.Compose([ transforms.Resize((160, 160)), transforms.ToTensor(), ]) image_datasets =…
Ahmed Can Unbay
  • 2,694
  • 2
  • 16
  • 33
1
vote
1 answer

How to compute DTW distance more faster in massive data set

I try to calculate the distance between time series data using dtw in Python. There are 10487 time series data, and each time series data has 37 data points. I want to create a distance matrix of size 10487*10487 by calculating the distance between…
정재현
  • 11
  • 2
1
vote
2 answers

R: creating a distance matrix quickly (like using mapply() or similar)

I am looking to create a distance matrix for any arbitrary non-standard distance function. I can do this the slow way as follows: set.seed(1000) DF <- data.frame(x=rnorm(10),y=rnorm(10)) # ten random points on the x y plane L <- dim(DF)[1] …
Ingolifs
  • 290
  • 2
  • 14
1
vote
1 answer

How to create a graph from German OSM data with OSMnx efficiently?

I am currently working on a dataset with German postal codes. I aim to calculate "real" distances between the centers of each postal code area. To do so, I first downloaded the germany-latest.osm.bz2 file from geofabrik. Next I would like to create…
SpoJa92
  • 11
  • 1
1
vote
0 answers

How to enable Distance Matrix API ( Google API ) by restricting access from Android App?

Am using google's distance matric API in my Android Application https://maps.googleapis.com/maps/api/distancematrix/json?origins=10.016029902612894%2C76.40124697219122&destinations=10.000406199999999%2C76.31017589999999&key=*xxxxxxxxx* It worked…
1
vote
1 answer

Distance matrix between ALL features in ArcGIS

I have 20 000 polygons in a dataset. I need to have the Euclidean Distance between all polygons, so a 20 000 x 20 000 distance matrix where for each of the polygons, the distance to all other polygons is stored. I have read in some other threads the…
bram
  • 47
  • 6
1
vote
1 answer

recalculate distance matrix python OSRM docker in windows

I'm new to python programming please bear with me, I have calculated a distance matrix (300x300) using real data (lat & log) through a OSRM running in dockers in a windows machine. it takes about 400 secs to complete the calculation. because the…
mj_davis
  • 21
  • 3
1
vote
1 answer

create distance_matrix using python dictionaries

I'm working on a facility location problem model and i would like to create a dictionary containing this distance matrix, distance_matrix I want the keys to correspond to the combination between first element of each row and the header like this…
1
vote
2 answers

Creating a pairwise distance matrix in Julia from triplets (obj, obj, distance/simularity)

I have a matrix that is in the form of "obj obj distance" a toy matrix would look like this: r = [[1,1,1,2,2,2,3,3,3] [1,2,3,1,2,3,1,2,3] [0,.5,.75,.75,0,.25,.5,.25,0]] I currently have a solution along the lines of: using NamedArrays function…
1
vote
2 answers

Find the distance between each element and the centroid based on distance matrix?

I have a distance matrix (pairwise distance between elements) and I would like to find the centroid of the set and get the distance between each element and the centroid. I was trying to use k-means to do it and set the n_clusters=1 km =…
1
vote
1 answer

Matrix of "for x in vectors: for y in vectors:", without two for loops

Can one get the cartesian outer product of two set of vectors without using two for loops? It is slow because the data is large. [[f(x,y) for x in vectors] for y in vectors] I am trying to do an agglomerative clustering project in python and for…
1
vote
2 answers

preventing insert on duplicate values Postgres

I am building a distance matrix with this SQL statement: INSERT INTO tabel (start, end, agg_cost) SELECT * FROM pgr_dijkstraCostMatrix( 'SELECT id, source, target, cost, reverse_cost FROM edges', (SELECT array_agg(id) FROM vertices …
Maas
  • 25
  • 5
1
vote
0 answers

Create normalized pairwise matrix from trajectories with geographic coordinates R

I am dealing with a R list of geographic coordinates that embodies trajectories of drifters during a given period. My list of data frames looks like this : > str(traj_svp_sarg_from_d) List of 5 $ SVP_undrogued_ID_4101647 :'data.frame': …
Sarah.B
  • 11
  • 3
1
vote
1 answer

How to build efficiently a distance matrix by reshaping numpy array arrays for scipy.cdist or using sklearn?

I am trying to build a distance matrix with array of different lenghts. The distance metric is hausdorff distance which is suitable for this kind of operations. Nonetheless I cant find a way to build a distance matrix using the scipy.cdist…
DaveR
  • 1,696
  • 18
  • 24
1
vote
0 answers

Compute pairwise geospatial distance matrix using GeoPandas

I have a large array that has user IDs and their respective geospatial locations at different times. I am trying to rank these users in terms of their geospatial activity; that is, how much each user moves around, on average. Hence, I am trying to…
CopyOfA
  • 767
  • 5
  • 19