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.

In mathematics, 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. By using this formula as distance, Euclidean space (or even any inner product space) becomes a metric space. The associated norm is called the Euclidean norm.

http://en.wikipedia.org/wiki/Euclidean_distance

941 questions
9
votes
5 answers

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: And I think I can do it if I use this…
VansFannel
  • 45,055
  • 107
  • 359
  • 626
9
votes
1 answer

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 point in the set from the given point. There are…
9
votes
7 answers

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], [5, 6], [7, 8]]…
Ηλίας
  • 2,560
  • 4
  • 30
  • 44
9
votes
2 answers

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 is minimized? For example, import…
Keith Hughitt
  • 4,860
  • 5
  • 49
  • 54
9
votes
6 answers

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 sqrtf((float)((px)*(px)+(py)*(py))); } Thanks in…
Pol
  • 103
  • 1
  • 2
  • 8
8
votes
4 answers

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 dimension then, is it still possible to use…
Maggie
  • 5,923
  • 8
  • 41
  • 56
8
votes
2 answers

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(column1 - column2) result = zero_data.apply(lambda…
Quicklearner.gk
  • 133
  • 1
  • 1
  • 8
8
votes
2 answers

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 scipy.spatial.distance import cdist def ABdist(A,…
Gabriel
  • 40,504
  • 73
  • 230
  • 404
8
votes
3 answers

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

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 distance from ith point of mx2 matrix to jth…
user_1_1_1
  • 903
  • 1
  • 12
  • 27
8
votes
3 answers

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 dimensional vector (N=1024). The training dataset has…
user1462351
  • 133
  • 1
  • 1
  • 6
8
votes
1 answer

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 way I can do it successful is using the following…
user1121588
8
votes
1 answer

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 I0805 11:10:16.976716 1936085760 solver.cpp:229] …
user3543300
  • 499
  • 2
  • 9
  • 27
8
votes
2 answers

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 could work out till…
user14845
  • 95
  • 1
  • 6
8
votes
1 answer

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 coordinates, but a different one for the hours…
7
votes
1 answer

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 using Scipy (= option 1): distance =…
Silas Berger
  • 129
  • 6
1 2
3
62 63