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
790 votes
26 answers
1.4m views

How can the Euclidean distance be calculated with NumPy?

I have two points in 3D space: a = (ax, ay, az) b = (bx, by, bz) I want to calculate the distance between them: dist = sqrt((ax-bx)^2 + (ay-by)^2 + (az-bz)^2) How do I do this with NumPy? I have: ...
Nathan Fellman's user avatar
46 votes
9 answers
62k views

Minimum Euclidean distance between points in two different Numpy arrays, not within

I have two arrays of x-y coordinates, and I would like to find the minimum Euclidean distance between each point in one array with all the points in the other array. The arrays are not necessarily the ...
fideli's user avatar
  • 3,243
44 votes
2 answers
21k views

Compare similarity algorithms

I want to use string similarity functions to find corrupted data in my database. I came upon several of them: Jaro, Jaro-Winkler, Levenshtein, Euclidean and Q-gram, I wanted to know what is ...
Ali's user avatar
  • 818
41 votes
4 answers
35k views

Vector Space Model: Cosine Similarity vs Euclidean Distance

I have corpora of classified text. From these I create vectors. Each vector corresponds to one document. Vector components are word weights in this document computed as TFIDF values. Next I build a ...
Anton Ashanin's user avatar
35 votes
5 answers
109k views

python numpy euclidean distance calculation between matrices of row vectors

I am new to Numpy and I would like to ask you how to calculate euclidean distance between points stored in a vector. Let's assume that we have a numpy.array each row is a vector and a single numpy....
pacodelumberg's user avatar
32 votes
5 answers
61k views

Efficiently Calculating a Euclidean Distance Matrix Using Numpy

I have a set of points in 2-dimensional space and need to calculate the distance from each point to each other point. I have a relatively small number of points, maybe at most 100. But since I need ...
Wes Modes's user avatar
  • 2,074
27 votes
2 answers
38k views

Is "norm" equivalent to "Euclidean distance"?

I am not sure whether "norm" and "Euclidean distance" mean the same thing. Please could you help me with this distinction. I have an n by m array a, where m > 3. I want to calculate the Eculidean ...
J_yang's user avatar
  • 2,702
22 votes
6 answers
38k views

Find the shortest distance between a point and line segments (not line)

I have set of line segments (not lines), (A1, B1), (A2, B2), (A3, B3), where A,B are ending points of the line segment. Each A and B has (x,y) coordinates. QUESTION: I need to know the shortest ...
Spider's user avatar
  • 977
21 votes
7 answers
36k views

Multidimensional Euclidean Distance in Python

I want to calculate the Euclidean distance in multiple dimensions (24 dimensions) between 2 arrays. I'm using numpy-Scipy. Here is my code: import numpy,scipy; A=numpy.array([116.629, 7192.6, 4535....
garak's user avatar
  • 4,733
21 votes
3 answers
42k views

Distance calculation between rows in Pandas Dataframe using a distance matrix

I have the following Pandas DataFrame: In [31]: import pandas as pd sample = pd.DataFrame({'Sym1': ['a','a','a','d'],'Sym2':['a','c','b','b'],'Sym3':['a','c','b','d'],'Sym4':['b','b','b','a']},index=[...
Clayton's user avatar
  • 1,545
19 votes
3 answers
30k views

Calculate Euclidean distance between 4-dimensional vectors

Let's say I have two 4-dimensional vectors (i.e. a and b) as follows: a = {a1, a2, a3, a4} b= {b1, b2, b3, b4} How do I compute the Euclidean distance between these vectors?
user3583442's user avatar
16 votes
1 answer
5k views

Calculate signed distance between point and rectangle

I'm trying to write a function in GLSL that returns the signed distance to a rectangle. The rectangle is axis-aligned. I feel a bit stuck; I just can't wrap my head around what I need to do to make it ...
tenfour's user avatar
  • 36.4k
15 votes
3 answers
12k views

Euclidean distance between two n-dimensional vectors

What's an easy way to find the Euclidean distance between two n-dimensional vectors in Julia?
JobJob's user avatar
  • 3,937
15 votes
3 answers
2k views

Efficient calculation of euclidean distance

I have a MxN array, where M is the number of observations and N is the dimensionality of each vector. From this array of vectors, I need to calculate the mean and minimum euclidean distance between ...
japata's user avatar
  • 329
14 votes
5 answers
21k views

Fastest way to calculate the distance between two CGPoints?

Distance between two points: sqrt((x1-x2)^2 + (y1-y2)^2) Is there a way to do this math faster in objective-C ? EDIT: I think I need to clarify above. I wrote the formula above just to clarify what ...
xcoder's user avatar
  • 967
14 votes
6 answers
23k views

Efficient and precise calculation of the euclidean distance

Following some online research (1, 2, numpy, scipy, scikit, math), I have found several ways for calculating the Euclidean Distance in Python: # 1 numpy.linalg.norm(a-b) # 2 distance.euclidean(...
user avatar
13 votes
2 answers
5k views

Efficiently compute pairwise squared Euclidean distance in Matlab

Given two sets of d-dimensional points. How can I most efficiently compute the pairwise squared euclidean distance matrix in Matlab? Notation: Set one is given by a (numA,d)-matrix A and set two is ...
matheburg's user avatar
  • 2,120
12 votes
3 answers
25k views

OpenCV euclidean distance between two vectors

I want to calculate the euclidean distance between two vectors (or two Matrx rows, doesn't matter). Is there a good function for that in OpenCV?
farahm's user avatar
  • 1,306
12 votes
3 answers
32k views

Distance between nodes and the centroid in a kmeans cluster?

Any option to extract the distance between the nodes and the centroid in a kmeans cluster. I have done Kmeans clustering over an text embedding data set and I want to know which are the nodes that ...
VIJU's user avatar
  • 156
11 votes
2 answers
18k views

Find euclidean distance from a point to rows in pandas dataframe

i have a dataframe id lat long 1 12.654 15.50 2 14.364 25.51 3 17.636 32.53 5 12.334 25.84 9 32.224 15.74 I want to find the euclidean distance of these ...
Shubham R's user avatar
  • 7,562
11 votes
3 answers
10k views

How to get cosine distance between two vectors in postgres?

I am wondering if there is a way to get cosine distance of two vectors in postgres. For storing vectors I am using CUBE data type. Below is my table definition: test=# \d vectors ...
Anant's user avatar
  • 3,077
11 votes
3 answers
14k views

How to convert distance into probability?

Сan anyone shine a light to my matlab program? I have data from two sensors and i'm doing a kNN classification for each of them separately. In both cases training set looks like a set of vectors of 42 ...
niko_dry's user avatar
  • 111
11 votes
1 answer
3k views

Example of increasing the work per thread in CUDA

Algorithm : I'm writing a program with CUDA and the problem is the following: Two matrices A (n * 128) and B (m * 128) I take the first row of A, and I compute the distance between that vector and ...
user avatar
11 votes
5 answers
6k views

What is the most efficient way to find the euclidean distance in 3d using mysql?

I have a MySQL table with thousands of data points stored in 3 columns R, G, B. how can I find which data point is closest to a given point (a,b,c) using Euclidean distance? I'm saving RGB values of ...
soulkphp's user avatar
  • 3,783
10 votes
1 answer
13k views

Compute Euclidean distance between rows of two pandas dataframes

I have two pandas dataframes d1 and d2 that look like these: d1 looks like: output value1 value2 value2 1 100 103 87 1 201 97.5 88.9 1 ...
j1897's user avatar
  • 1,547
10 votes
4 answers
14k views

Pyspark euclidean distance between entry and column

I am working with pyspark, and wondering if there is any smart way to get euclidean dstance between one row entry of array and the whole column. For instance, there is a dataset like this. +----------...
Yong Hyun Kwon's user avatar
10 votes
4 answers
22k views

How to find the nearest neighbors of 1 Billion records with Spark?

Given 1 Billion records containing following information: ID x1 x2 x3 ... x100 1 0.1 0.12 1.3 ... -2.00 2 -1 1.2 2 ... 3 ... For each ID above, I want to find the ...
Osiris's user avatar
  • 1,017
10 votes
4 answers
56k views

How to calculate Euclidian distance between two points defined by matrix containing x, y?

I am very lost in Euclidean distance calculation. I have found functions dist2{SpatialTools} or rdist{fields} to do this, but they doesn´t work as expected. I suppose that one point has two ...
maycca's user avatar
  • 3,980
10 votes
5 answers
11k views

Compute L2 distance with numpy using matrix multiplication

I'm trying to do it by myself the assignments from Stanford CS231n 2017 CNN course. I'm trying to compute L2 distance using only matrix multiplication and sum broadcasting with Numpy. L2 distance is: ...
VansFannel's user avatar
  • 45.4k
10 votes
1 answer
5k views

Most Efficient Way to Calculate an SDF to a Triangle Mesh

Hi. I've been gathering info from various sources consistently over the past month, yet without any luck of finding an idea that would suit my particular issue. So here's the formulation of the ...
Martin's user avatar
  • 151
9 votes
7 answers
10k views

Identifying points with the smallest Euclidean distance

I have a collection of n dimensional points and I want to find which 2 are the closest. The best I could come up for 2 dimensions is: from numpy import * myArr = array( [[1, 2], [3, 4]...
Ηλίας's user avatar
  • 2,600
9 votes
2 answers
7k views

Minimize total distance between two sets of points in Python

Given two sets of points in n-dimensional space, how can one map points from one set to the other, such that each point is only used once and the total euclidean distance between the pairs of points ...
Keith Hughitt's user avatar
9 votes
6 answers
22k views

Fastest way to calculate Euclidean distance in c

I need to calculate euclidean distance between two points in the fastest way possible. In C. My code is this and seems a little bit slow: float distance(int py, int px, int jy, int jx){ return ...
Pol's user avatar
  • 103
9 votes
4 answers
10k views

Euclidean distance with weights

I am currently using SciPy to calculate the euclidean distance dis = scipy.spatial.distance.euclidean(A,B) where; A, B are 5-dimension bit vectors. It works fine now, but if I add weights for each ...
Maggie's user avatar
  • 5,963
9 votes
3 answers
5k views

pdist2 equivalent in MATLAB version 7

I need to calculate the euclidean distance between 2 matrices in matlab. Currently I am using bsxfun and calculating the distance as below( i am attaching a snippet of the code ): for i=1:4754 ...
bhavs's user avatar
  • 2,181
9 votes
1 answer
3k views

How to find the farthest point (from a set of points) from a given point efficiently?

I'm looking for an algorithm or data structure to solve the following problem: You are given a set of points S. And you are given Q queries in form of another point. For every query, find the farthest ...
Nikola Pesic's user avatar
8 votes
3 answers
14k views

Memory Efficient L2 norm using Python broadcasting

I am trying to implement a way to cluster points in a test dataset based on their similarity to a sample dataset, using Euclidean distance. The test dataset has 500 points, each point is a N ...
user1462351's user avatar
8 votes
3 answers
23k views

Python alternative for calculating pairwise distance between two sets of 2d points [duplicate]

In Matlab there exists the pdist2 command. Given the matrix mx2 and the matrix nx2, each row of matrices represents a 2d point. Now I want to create a mxn matrix such that (i,j) element represents the ...
user_1_1_1's user avatar
8 votes
1 answer
4k views

einsum and distance calculations

I have searched for a solution to determine distances using einsum for numpy arrays that are not equal in their number of rows, but equal in columns. I have tried various combinations but the only ...
user avatar
8 votes
2 answers
16k views

Calculating pairwise Euclidean distance between all the rows of a dataframe

How can I calculate the Euclidean distance between all the rows of a dataframe? I am trying this code, but it is not working: zero_data = data distance = lambda column1, column2: pd.np.linalg.norm(...
Quicklearner.gk's user avatar
8 votes
2 answers
3k views

Find minimum distances between groups of points in 2D (fast and not too memory consuming)

I have two sets of points in 2D A and B and I need to find the minimum distance for each point in A, to a point in B. So far I've been using SciPy's cdist with the code below import numpy as np from ...
Gabriel's user avatar
  • 41.7k
8 votes
2 answers
8k views

calculating the euclidean dist between each row of a dataframe with all other rows in another dataframe

I need to generate a dataframe with minimum euclidean distance between each row of a dataframe and all other rows of another dataframe.Both my dataframes are large (approx 40,000 rows).This is what I ...
user14845's user avatar
  • 105
8 votes
1 answer
5k views

Caffe Iteration loss versus Train Net loss

I'm using caffe to train a CNN with a Euclidean loss layer at the bottom, and my solver.prototxt file configured to display every 100 iterations. I see something like this, Iteration 4400, loss = 0 ...
user3543300's user avatar
8 votes
1 answer
2k views

Clustering in python(scipy) with space and time variables

The format of my dataset: [x-coordinate, y-coordinate, hour] with hour an integer value from 0 to 23. My question now is how can I cluster this data when I need an euclidean distance metric for the ...
user2768102's user avatar
7 votes
2 answers
11k views

Pycuda Blocks and Grids to work with big datas

I need help to know the size of my blocks and grids. I'm building a python app to perform metric calculations based on scipy as: Euclidean distance, Manhattan, Pearson, Cosine, joined other. The ...
Vinnicyus Gracindo's user avatar
7 votes
1 answer
6k views

Calculating euclidean distance between consecutive points of an array with numpy

I have an array which describes a polyline (ordered list of connected straight segments) as follows: points = ((0,0), (1,2), (3,4), (6,5), (10,3), (...
heltonbiker's user avatar
  • 27.2k
7 votes
1 answer
802 views

Euclidean distance, different results between Scipy, pure Python, and Java

I was playing around with different implementations of the Euclidean distance metric and I noticed that I get different results for Scipy, pure Python, and Java. Here's how I compute the distance ...
Silas Berger's user avatar
6 votes
4 answers
4k views

Euclidian Distance Python Implementation

I am playing with the following code from programming collective intelligence, this is a function from the book that calculated eclidian distance between two movie critics. This function sums the ...
Hamza Yerlikaya's user avatar
6 votes
5 answers
16k views

How to calculate Euclidean length of a matrix without loops?

It seems like the answer to this should be simple, but I am stumped. I have a matrix of Nx3 matrix where there 1st 2nd and 3rd columns are the X Y and Z coordinates of the nth item. I want to ...
Miebster's user avatar
  • 2,405
6 votes
2 answers
9k views

Creating a distance matrix from a list of coordinates in R

I have a csv file with a list of co-ordinate positions for over 2000 farms, with the following structure; FarmID | Latidue | Longitude | ------ |---------|-----------| 1 | y1 | x1 ...
sruby52's user avatar
  • 83

1
2 3 4 5
19