Questions tagged [euclidean-distance]

the Euclidean distance or Euclidean metric is the "ordinary" distance between two points that one would measure with a ruler, and is given by the Pythagorean formula.

euclidean-distance
Filter by
Sorted by
Tagged with
3 votes
1 answer
6k views

Calculate overlap between two rectangles on x/y grid?

I need to calculate the overlap (amount or yes/no) that two rectangles make on a special x/y grid. The grid is 500x500 but the sides and corners connect (are continuous). So the next point after 499 ...
Ropstah's user avatar
  • 17.7k
3 votes
1 answer
196 views

Optimise Euclidean distance matrix algorithm if only interested in closest points

The following Euclidean distance algorithm creates a MxM matrix of distances between the rows of an MxN input matrix (representative of points in some N dimensional space). The speed of this algorithm ...
Atticus's user avatar
  • 176
3 votes
2 answers
2k views

What is the fastest way to compute the Euclidean distances of a very large matrix with complex numbers?

I have a very large input data set of 50,000 samples with 9 dimensions (i.e. a 50000x9 matrix). This data has been transformed using DFT: dft_D = data.dot(dft(9).T) / np.sqrt(9) I want to calculate ...
mtruong1999's user avatar
3 votes
2 answers
2k views

Fastest way to calculate the shortest (euclidean) distance between points, in pandas dataframe

Consider the following pandas dataframe: print(df) Id X Y Type X of Closest Y of Closest 0 201 73.91 34.84 A NaN NaN 1 201 74.67 32.64 A ...
MRHarv's user avatar
  • 503
3 votes
1 answer
947 views

How to use apply function to calculate the distance between two matrices

I'm trying to calculate the euclidean distance between two matrices. I have already achieved that using 2 for loops but trying to vectorize the calculation to speed up. I'm using pdist as a benchmark ...
Ray's user avatar
  • 59
3 votes
1 answer
2k views

How to calculate weighted similarity with scipy.spatial.distance.cosine?

From the function definition: https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cosine.html scipy.spatial.distance.cosine(u, v, w=None) but my codes got some errors: from ...
DataHolic's user avatar
3 votes
2 answers
2k views

fastest way to get closest 10 euclidean neighbors of large feature vector in python

I have a numpy array that has 10,000 vectors with 3,000 elements in each. I want to return the top 10 indices of the closest pairs with the distance between them. So if row 5 and row 7 have the ...
Mike El Jackson's user avatar
3 votes
1 answer
645 views

(Eucledian Shortest Path) Detecting corners of obstacles in plane

Problem History/ Origin Lately I stumbled over channels on Twitch.TV from players that perform speedruns of classic games. One of them played The Legend of Zelda - A Link to the Past. I saw many ...
Benj's user avatar
  • 949
3 votes
2 answers
522 views

How to pull points that are within a certain distance away in R?

I have a parameter space given by (x,y) with x values from 1:5 and y values from 1:8. Let's say my current point p is located at (2,5) (it is colored in red). My goal is to try to pull all the points ...
road_to_quantdom's user avatar
3 votes
3 answers
3k views

Calculating Euclidean distance of pairs of 3D points in matlab

I have an Nx3 array that contains N 3D points a1 b1 c1 a2 b2 c2 .... aN bN cN I want to calculate Euclidean distance in a NxN array that measures the Euclidean distance between each pair of 3D ...
Mojtaba's user avatar
  • 33
3 votes
1 answer
7k views

calculate Euclidean distance of two image in hsv color space in matlab

i use the code below to calculate the Euclidean distance for two rgb images: Im1 = imread(filename1); Im1 = rgb2gray(Im1); hn1 = imhist(Im1)./numel(Im1); Im2 = imread(filename2); Im2 = rgb2gray(Im2); ...
samdean's user avatar
  • 113
3 votes
2 answers
7k views

Euclidean distance between two set of 3D points

How can I find the nearest points of two set of 3D points(with different number,set1 includes 400 points and set2 includes 2000 points) and then find the Euclidean distance between set1 and result ...
john MacL's user avatar
3 votes
2 answers
1k views

squared-euclidean distance with RealVectors in Apache Commons Math

I'm using Apache Commons RealVector and ArrayRealVector classes in Java. I can calculate the euclidean distance between two vectors v1 and v2 as double dist = v1.getDistance(v2); However, I'm ...
COM's user avatar
  • 847
3 votes
1 answer
303 views

Euclidean Distance for Arrays of 3D points in Python

I have two .csv files of 3D points (numeric coordinate data) and associated attribute data (strings + numeric). I need to calculate the Euclidean distance between each point and every other point, and ...
COIh0rp's user avatar
  • 63
3 votes
2 answers
1k views

euclidean distance calculation using Python and Dask

I'm attempting to identify elements in the euclidean distance matrix that fall under a certain threshold. I then take the positional arguments for this search and use them to compare elements in a ...
Quinn Anderson's user avatar
3 votes
1 answer
2k views

Python: how to compute the Euclidean distance distribution of a regular network?

I have an NxN regular network, each node of which has an (X,Y) set of coordinates. The nodes are separated by the unit. The network looks like this: (0,0) (1,0) (2,0) (0,1) (1,1) (2,1) (0,2) (1,2) (2,...
FaCoffee's user avatar
  • 7,759
3 votes
1 answer
1k views

How to calculate the euclidean distance in Python without fixed-dimension?

I intend to calculate the euclidean distance between two sets of big data. I've googled that the module called SciPy will do the work, whose mechanism is via k-d tree. But I don't have fixed ...
Judking's user avatar
  • 6,211
3 votes
1 answer
2k views

How to compare great circle distance with euclidean distance of two sphere points using python?

I am trying to check the error that is introduced when you compute the distance of two points on earth with the euclidean distance instead of using the great circle distance (gcd). I have two points ...
curious's user avatar
  • 1,552
3 votes
1 answer
2k views

Euclidean distance in R using two variables in a matrix

I am quite new to R and I am trying to compute the gross distance (or the sum of the Euclidean distance on all data points) from two variables in my matrix and net distance (Euclidean distance between ...
Kaye11's user avatar
  • 359
3 votes
1 answer
784 views

Making an Euclidean Distance Matrix with Random Points in Python

I wrote a code that produces the desired number of points in a certain width and length range in the coordinate system. How can I calculate and tabulate the distance matrix of these points I produced ...
user avatar
3 votes
0 answers
109 views

Distance Metric different units

I am trying to cluster a radar database. The observations of a radar are given in Azimuth angle and range. For processing speed reasons I do not want to transform this polar data into a Cartesian ...
Metz's user avatar
  • 73
3 votes
0 answers
113 views

How to calculate euclidean distance of a column with all the sublist of another column with respect to grouping in pandas dataframe?

I have following dataframe, mac1 mac2 uuid val refVal 0 ...
anu010291's user avatar
3 votes
0 answers
3k views

Normalising Data to use Cosine Distance in Kmeans (Python)

I am currently solving a problem where I have to use Cosine distance as the similarity measure for Kmeans clustering. However, the standard Kmeans clustering package (from Sklearn package) uses ...
MSalty's user avatar
  • 4,344
3 votes
0 answers
1k views

How to calculate minimum euclidean distance between two point sets with permutable elements?

I'm working with two sets of points which always have the same number of elements. A0–An and B0–Bn. Both of these sets are non-ordered. [Image 1] I need to calculate minimum possible euclidean ...
ponney's user avatar
  • 31
3 votes
0 answers
3k views

Python Networkx - Visualizing a distance matrix

I'm tyring to use Networkx to visualize a distance matrix. What I want is a graph where the edge length between nodes is proportional to the distance between them in the distance matrix. I wrote the ...
user1893354's user avatar
  • 5,848
2 votes
7 answers
5k views

Pairwise Distance Calculation in c++

I'm computing the potential energy of a large (~1e5) number of particles in c++. In order to do this, I'm running a double loop in which I calculate pairwise distances, and from those distance compute ...
astromax's user avatar
  • 6,071
2 votes
3 answers
199 views

How to vectorize finding the closest point out of a vector

BigList = rand(20, 3) LittleList = rand(5, 3) I'd like to find for each row in the big list the 'closest' row in the little list, as defined by the euclidean norm (i.e. sum of squared distances ...
Rob Donnelly's user avatar
  • 2,256
2 votes
2 answers
271 views

Apply EuclideanDistance at a certain level in Mathematica

Please consider: daList = {{{21, 18}, {20, 18}, {18, 17}, {20, 15}}, {{21, 18}, {20, 18}, {21, 14}, {21, 14}}}; I would like to compute the distance between each point in the 2 sub-lists ...
500's user avatar
  • 6,569
2 votes
3 answers
2k views

How to calculate Euclidean distance in R for n-dimensions?

I'm trying to write a function which calculates Euclidean distance between two points across n-dimensions. I have the following code: euc_dist <- function(x1, x2) sqrt(sum((x1 - x2) ^ 2)) This ...
HelpNeeded3's user avatar
2 votes
1 answer
4k views

Distance between two 3D points in R

I have two 2 points A(x,y,z) e B(x1,y1,z1). I want to calculate the euclidean distance between these point at time1, time2, time3. So, I have a matrix like this: x y z x1 y1 ...
piravi's user avatar
  • 109
2 votes
3 answers
4k views

Calculate euclidean distance from dicts (sklearn)

I have two dictionaries already calculated in my code, which look like this: X = {'a': 10, 'b': 3, 'c': 5, ...} Y = {'a': 8, 'c': 3, 'e': 8, ...} Actually they contain words from wiki texts, but ...
Zelphir Kaltstahl's user avatar
2 votes
6 answers
23k views

Calculate Euclidean distance between two python arrays

I want to write a function to calculate the Euclidean distance between coordinates in list_a to each of the coordinates in list_b, and produce an array of distances of dimension a rows by b columns (...
N86808's user avatar
  • 45
2 votes
1 answer
13k views

Implementing k-means with Euclidean distance vs Manhattan distance?

I am implementing kmeans algorithm from scratch in python and on Spark. Actually, it is my homework. The problem is to implement kmeans with predefined centroids with different initialization methods, ...
mrasoolmirza's user avatar
2 votes
2 answers
2k views

Pairwise Euclidean distance with pandas ignoring NaNs

I start with a dictionary, which is the way my data was already formatted: import pandas as pd dict2 = {'A': {'a':1.0, 'b':2.0, 'd':4.0}, 'B':{'a':2.0, 'c':2.0, 'd':5.0}, 'C':{'b':1.0,'c':2.0, 'd':4....
Jabernet's user avatar
  • 401
2 votes
3 answers
4k views

How to efficiently calculate euclidean distance matrix for several timeseries

I have 6 timeseries data as follows namely t1, t2, t3, t4, t5 and t6. import numpy as np series = np.array([ [0., 0, 1, 2, 1, 0, 1, 0, 0], [0., 1, 2, 0, 0, 0, 0, 0, 0], [1., 2, 0, 0, 0,...
EmJ's user avatar
  • 4,508
2 votes
2 answers
185 views

Select data by euclidean distance with awk

I have a big ASCII datafile and want to select the data by the Euclidean distance MINDISTANCE=5.2 to some point (x0, y0, z0)=(1,2,3). In other words if(sqrt((x0-v2)^2+(y0-v3)^2+(z0-v4)^2))>MINDISTANCE)...
Jojo's user avatar
  • 75
2 votes
5 answers
3k views

Calculate Euclidean distances between all rows in matrices A and B

I have two matrices, A and B, with N_a and N_b rows, respectively. I need to calculate the Euclidean distance between all pairwise combinations of an element in A (a) and another in B (b), such that ...
Henry David Thorough's user avatar
2 votes
2 answers
4k views

How can I find the perpendicular distance between two parallel line segments?

I have many parallel line segments, for example L1(P1, P2) and L2(P3, P4). The Points have each x and y coordinates. These parallel line segments have varying angles between 0-180 degrees. How can I ...
baal's user avatar
  • 257
2 votes
1 answer
251 views

Euclidian Distance math error

import math from math import sqrt Hailey=[0,4,1,4,0,0,4,1] Verica=[3,0,0,5,4,2.5,3,0] temp=[] distance=0 x=0 for i in range(0,len(Hailey)): if (Hailey[i]!=0 and Verica[i]!=0): temp[x]=...
IseNgaRt's user avatar
  • 611
2 votes
2 answers
1k views

R User-defined function works alone but returns incorrect values when used with apply

The user defined function (dist.func) runs and provides the correct output when I use it on a single line of data but does not provide the correct output (still executes) when I embed it into the ...
David Roberts's user avatar
2 votes
1 answer
2k views

octave pdist (pairwise distance)

The octave documentation says pdist exists, but I cannot use it in my version installed on ubuntu 12.04. Octave version: GNU Octave, version 3.6.2 Copyright (C) 2012 John W. Eaton and others. This ...
Vahid Mirjalili's user avatar
2 votes
3 answers
607 views

Calculate distances among a set of coordinates

Is there a more efficient way to calculate the Euclidean distance among a given set of points? This is the code I use: def all_distances(position): distances = np.zeros((N_circles, N_circles)) ...
Federico Mancini's user avatar
2 votes
2 answers
227 views

Compute the difference matrix between a matrix and another matrix in MATLAB

Given a matrix A in matlab with: 3 1 4 5 7 8 and another matrix B which could be referred to as some reference points (each row is reference point that is to be compared to each row of A), 1 ...
Jesujoba Oluwadara ALABI's user avatar
2 votes
2 answers
344 views

How to improve processing time for euclidean distance calculation

I'm trying to calculate the weighted euclidean distance (squared) between twoo data frames that have the same number of columns (variables) and different number of rows (observations). The ...
Ana F.'s user avatar
  • 43
2 votes
2 answers
1k views

Calculating pairwise spatial distances in periodic 2D lattice

I've been searching in vain for a solution to compute spatial distances between discrete, equidistant square sites on a lattice of periodic/wrapped edges. For example, setting adjacent sites to be 2 ...
neither-nor's user avatar
  • 1,243
2 votes
1 answer
1k views

Confuse with sklearn distance algorithm

While I want to use standard Euclidean metric in KNeighborsClassifier. knn = KNeighborsRegressor(n_neighbors=k,metric='seuclidean' ) knn.fit(newx,y) and the typeerror shown: C:\Anaconda3\lib\site-...
Li Ziming's user avatar
  • 385
2 votes
1 answer
961 views

Min Cost Flow Optimized for a Complete Bipartite Matching in Euclidean Space

The gist is... we have two sets of points A and B. Set A and B have the same number of points n. Formal Problem: Construct a minimum cost complete bipartite matching between points in A and B. The ...
Michael Petrochuk's user avatar
2 votes
2 answers
4k views

Measuring person's height using Kinect

I am trying to calculate the height of a person using Kinect. Here is how I calculate the height (this code is not very sophisticated, it is only for testing purposes): double h2s = Math.Sqrt(Math....
user2179427's user avatar
2 votes
2 answers
214 views

Automating (loops) Euclidean distance measurements in R

AIM: I want to automate (loop) the code below, without having to manually run it for each sample. I have a terrible habit of writing long-hand in base, and need to start using loops, which I find ...
Rchaeologist's user avatar
2 votes
2 answers
2k views

Vectorize the calculation for Euclidean distance between matrix and vector

I want to calculate the Euclidean distance between matrices and a standard vector. All my matrices are stored in a list, let's say, A, so that A = [[1,2,3],[2,3,4]...,[8,9,10]], And the standard ...
HAOYANG MI's user avatar

1 2 3
4
5
19