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
950
questions
6
votes
2
answers
5k
views
R - How to get row & column subscripts of matched elements from a distance matrix
I have an integer vector vec1 and I am generating a distant matrix using dist function. I want to get the coordinates (row and column) of element of certain value in the distance matrix. Essentially I ...
6
votes
1
answer
4k
views
Calculate the euclidian distance between an array of points to a line segment in Python without for loop
I'm looking for a function to compute the euclidian distance between a numpy array of points with two coordinates (x, y) and a line segment. My goal is to have a result in under 0.01 sec for a line ...
6
votes
1
answer
6k
views
Why cdist from scipy.spatial.distance is so fast?
I wanted to create a distance proximity matrix for 10060 records/ points, where each record/point has 23 attributes using euclidean distance as metric. I wrote code using nested for loops to calculate ...
6
votes
3
answers
5k
views
Numpy: find the euclidean distance between two 3-D arrays
Given, two 3-D arrays of dimensions (2,2,2):
A = [[[ 0, 0],
[92, 92]],
[[ 0, 92],
[ 0, 92]]]
B = [[[ 0, 0],
[92, 0]],
[[ 0, 92],
[92, 92]]]
How do you find the Euclidean ...
6
votes
2
answers
1k
views
Matlab formula optimization: Radial Basis Function
z - matrix of doubles, size Nx2;
x - matrix of doubles, size Nx2;
sup = x(i, :);
phi(1, i) = {@(z) exp(-g * sum((z - sup(ones([size(z, 1) 1]),:)) .^ 2, 2))};
this is a Radial Basis Function (RBF) ...
6
votes
1
answer
966
views
trying to draw circles based on distance between points
I'm trying to draw some circles and I was sort of hoping they would intersect with some points, alas...
library(maptools)
library(plotrix)
xy <- matrix(runif(20, min = -100, max = 100), ncol = 2)
...
6
votes
1
answer
6k
views
Weighted Euclidean Distance in R
I'd like to create a distance-matrix with weighted euclidean distances from a data frame. The weights will be defined in a vector. Here's an example:
library("cluster")
a <- c(1,2,3,4,5)
b <- ...
6
votes
2
answers
95
views
Efficiently accessing pairwise distances
I have a distance matrix:
> mat
hydrogen helium lithium beryllium boron
hydrogen 0.000000 2.065564 3.940308 2.647510 2.671674
helium 2.065564 0.000000 2.365661 1.697749 1....
6
votes
4
answers
2k
views
Sum of distances from a point to all other points
I have two lists
available_points = [[2,3], [4,5], [1,2], [6,8], [5,9], [51,35]]
and
solution = [[3,5], [2,1]]
I'm trying to pop a point in available_points and append it to solution for which ...
6
votes
3
answers
3k
views
How to approximate Euclidean distance on the integer plane, without overflow?
I'm working on a platform that has only integer arithmetic. The application uses geographic information, and I'm representing points by (x, y) coordinates where x and y are distances measured in ...
5
votes
5
answers
14k
views
Calculating distance between two points in 3D
My assignment is to create main class in which I initialize the value of any point to be at (0,0,0) and to be able to access and mutate all three values (x,y,z) individually. To do this I have used ...
5
votes
1
answer
9k
views
Calculating Euclidian Norm in Pytorch.. Trouble understanding an implementation
I've seen another StackOverflow thread talking about the various implementations for calculating the Euclidian norm and I'm having trouble seeing why/how a particular implementation works.
The code ...
5
votes
3
answers
39k
views
Java methods getting euclidean distance
public class Point
{
// Placeholders for xcoordinate, ycoordinate, and quadrants
int xcoord = 0;
int ycoord =0;
double distance = 0.0;
String quadrant = ("NW");
//moveUp changes the y coordinate
...
5
votes
1
answer
3k
views
Best way to identify dissimilarity: Euclidean Distance, Cosine Distance, or Simple Subtraction?
I'm new to data science and am currently learning different techniques that I can do with Python. Currently, I'm trying it out with Spotify's API for my own playlists.
The goal is to find the most ...
5
votes
2
answers
4k
views
Distance matrix from two separate data frames
I'd like to create a matrix which contains the euclidean distances of the rows from one data frame versus the rows from another. For example, say I have the following data frames:
a <- c(1,2,3,4,5)...
5
votes
2
answers
4k
views
Calculate Euclidean Distance within points in numpy array
I have 3D array as
A = [[x1 y1 z1]
[x2 y2 z2]
[x3 y3 z3]]
I have to find euclidean distance between each points so that I'll get output with only 3 distance between (row0,row1),(row1,...
5
votes
1
answer
3k
views
Finding euclidean distance in R{spatstat} between points, confined by an irregular polygon window
I'm trying to find the euclidean distance between two points, confined by an irregular polygon. (ie. the distance would have to be calculated as a route through the window given)
Here is an ...
5
votes
1
answer
2k
views
What is the complexity of dist()?
I used the dist function in R and I am wondering the time complexity of it.
I know that the hierarchical clustering has a N^2*logN time complexity. And hierarchical clustering is composed of two ...
5
votes
7
answers
419
views
Find a shortest distance between two buckets of numbers
I have two buckets (unordered, 1-dimentional data structures) of numbers and I want to calculate a minimal distance between any elements of the two buckets. Is there a way to find the shortest ...
5
votes
4
answers
589
views
Vectorize mask of squared euclidean distance in Python
I'm running code to generate a mask of locations in B closer than some distance D to locations in A.
N = [[0 for j in range(length_B)] for i in range(length_A)]
dSquared = D*D
for i in range(...
5
votes
2
answers
3k
views
r distance between rows
I apologize this is my attempt at redeeming myself after a disastrous earlier attempt . Now I have a bit more clarity. So here I go again.
My goal is to find rows that are similar. So first I am ...
5
votes
2
answers
4k
views
How to implement callable distance metric in scikit-learn?
I'm using the clustering module in python's scikit learn, and I'd like to use a Normalized Euclidean Distance. There is no built-in distance for this (that i know of) Here's a list.
So, I want to ...
5
votes
2
answers
6k
views
Fastest way to Calculate the Euclidian distance between 2 sets of vectors using numpy or scipy
OK I have recently discovered that the the scipy.spatial.distance.cdist command is very quick for solving a COMPLETE distance matrix between two vector arrays for source and destination.
see: How can ...
5
votes
3
answers
761
views
Find the closest group of vectors, one vector from each set?
I have k sets of vectors. The vectors are all the same length m. The sets are not all the same length, but let's say they have an average length of n vectors in each. I need to find the group of ...
5
votes
0
answers
735
views
Getting distance to the hyperplane from sklearn's svm.svc
I'm currently using svc to separate two classes of data (the features below are named data and the labels are condition). After fitting the data using the gridSearchCV I get a classification score of ...
5
votes
2
answers
1k
views
How to efficiently find the two farthest point (Euclidean distance) in an 4-dimensional space given m points?
Given m 4-dimensional points, what is the efficient way to find out the two points that have the maximum Euclidean distance?
Currently, I am just using brute force approach and checking every pair ...
4
votes
3
answers
17k
views
How to calculate euclidean distance between pair of rows of a numpy array
I have a numpy array like:
import numpy as np
a = np.array([[1,0,1,0],
[1,1,0,0],
[1,0,1,0],
[0,0,1,1]])
I would like to calculate euclidian distance between ...
4
votes
8
answers
4k
views
Python: reduce on tuple of tuples
I am trying to compute in Python the length of the path from a point A to a point B going through a list of intermediary points. I know how to do it but I do want to use the reduce Built-in function.
...
4
votes
3
answers
3k
views
How much worse is sRGB than L*a*b* when computing the eucleidan distance between colors?
L*a*b* is the best way of doing it, but converting to it is complicated, and I'm lazy. How much accuracy am I giving up by operating on sRGB directly?
4
votes
3
answers
16k
views
In Numpy, find Euclidean distance between each pair from two arrays
I have two arrays of 2D coordinate points (x,y)
a = [ (x1,y1), (x2,y2), ... (xN,yN) ]
b = [ (X1,Y1), (X2,Y2), ... (XN,YN) ]
How can I find the Euclidean distances between each aligned pairs (xi,yi) ...
4
votes
4
answers
1k
views
(Speed Challenge) Any faster method to calculate distance matrix between rows of two matrices, in terms of Euclidean distance?
First of all, this is NOT the problem of calculating Euclidean distance between two matrices.
Assuming I have two matrices x and y, e.g.,
set.seed(1)
x <- matrix(rnorm(15), ncol=5)
y <- matrix(...
4
votes
2
answers
4k
views
calculating average distance of nearest neighbours in pandas dataframe
I have a set of objects and their positions over time. I would like to get the distance between each car and their nearest neighbour, and calculate an average of this for each time point. An example ...
4
votes
4
answers
3k
views
draw a graph where the distance between vertices correspond to the edge weights
Is there an algorithm that gives me coordinates of vertices in a graph, when I give him a weighted graph and the edge weights between vertices points to the distance between vertices?
Something like:
...
4
votes
3
answers
2k
views
Minimum distance between two axis-aligned boxes in n-dimensions
Question: How can I efficiently compute the minimum distance between two axis-aligned boxes in n-dimensions?
Box format: The boxes, A and B, are given by their minimum and maximum points, A_min, A_max,...
4
votes
2
answers
13k
views
Optimize performance for calculation of euclidean distance between two images
I implemented the k-nearest-neighbours algorithm in python to classify some randomly picked images from the mnist database. However I found my distance function to be quite slow: An analisys of 10 ...
4
votes
2
answers
1k
views
Euclidean Minimal Spanning Tree and Delaunay Triangulation
I want to calculate the minimal spanning tree based on the euclidean distance between a set of points on a 2D-plane. My current code stores all the edges, and then performs Prim's algorithm in order ...
4
votes
2
answers
5k
views
Calculate the euclidean distance in scipy csr matrix
I need to calculate the Euclidean Distance between all points that is stored in csr sparse matrix and some lists of points. It would be easier for me to convert the csr to a dense one, but I couldn't ...
4
votes
4
answers
3k
views
Faster way to compare two sets of points in N-dimensional space?
List1 contains a high number (~7^10) of N-dimensional points (N <=10), List2 contains the same or fewer number of N-dimensional points (N <=10).
My task is this: I want to check which point in ...
4
votes
4
answers
4k
views
How to apply euclidean distance function to a groupby object in pandas dataframe?
I have a set of objects and their positions over time. I would like to get the average distance between objects for each time point. An example dataframe is as follows:
time = [0, 0, 0, 1, 1, 2, 2]
x ...
4
votes
1
answer
2k
views
Continuous space shortest path
I need a shortest path algorithm for controlling a real life robot.
Lets say i have map of the environment in the form of a matrix where 1 is an obstacle and 0 is free space. If i use a conventional ...
4
votes
1
answer
5k
views
Vectorized implementation for Euclidean distance [duplicate]
I am trying to compute a vectorized implementation of Euclidean distance(between each element in X and Y using inner product). The data as follows:
X = np.random.uniform(low=0, high=1, size=(10000, 5)...
4
votes
1
answer
3k
views
Calculating Euclidean Distance With Given Lists
def distance(alist, blist):
sum_of = 0
for x in alist:
for y in blist:
ans = (x - y)**2
sum_of += ans
return (sum_of)**(1/2)
print(distance([1, 1, 3], [2, 2,...
4
votes
1
answer
3k
views
How to find the closest corresponding vectors between two coordinate matrices?
I have the following problem in Python I need to solve:
Given two coordinate matrices (NumPy ndarrays) A and B, find for all coordinate vectors a in A the corresponding coordinate vectors b in B, ...
4
votes
1
answer
384
views
NaN distances in Mahout Euclidean implementation
We're using the EuclideanDistanceSimilarity class to calculate the similarity of a bunch of items using Hadoop.
Unfortunately some items are getting zero or very few resulting similar items despite ...
4
votes
2
answers
4k
views
How to find the euclidian distance between the centroid of an object in one frame and the adjacent frame
We are doing a project in vehicle counting (using OpenCV). Now we have to find the euclidian distance from the centroid of the object in one frame to the adjacent frame? In our project we have done up ...
4
votes
1
answer
3k
views
Find distance to nearest neighbor in 2d array
I have a 2D array and I want to find for each (x, y) point the distance to its nearest neighbor as fast as possible.
I can do this using scipy.spatial.distance.cdist:
import numpy as np
from scipy....
4
votes
2
answers
4k
views
Error - Calculating Euclidean distance for PCA in python
I am trying to implement face recognition by Principal Component Analysis (PCA) using python. I am following the steps in this tutorial: http://onionesquereality.wordpress.com/2009/02/11/face-...
4
votes
1
answer
4k
views
Calculate squared Euclidean distance matrix on GPU
Let p be a matrix of first set of locations where each row gives the coordinates of a particular point. Similarly, let q be a matrix of second set of locations where each row gives the coordinates of ...
4
votes
2
answers
5k
views
Calculating a Voronoi diagram for planes in 3D
Is there a code/library that can calculate a Voronoi diagram for planes (parallelograms) in 3D? I checked Qhull and it seems it can only work with points, in its examples Voro++ works with different ...
4
votes
2
answers
5k
views
Can we cluster Multivariate Time Series dataset in Python
I have a dataset with many financial signal values for different stocks at different times.For example
StockName Date Signal1 Signal2
----------------------------------
Stock1 1/1/20 a ...