euclidean-distance

Finding squared distances beteen n points to m points in numpy

梦想与她 提交于 2021-02-19 06:23:06
问题 I have 2 numpy arrays(say X and Y) which each row represents a point vector. I want to find the squared euclidean distances(will call this 'dist') between each point in X to each point in Y. I want to the output to be a matrix D where D(i,j) is dist(X(i) , Y(j)). I have the following python code based on : http://nonconditional.com/2014/04/on-the-trick-for-computing-the-squared-euclidian-distances-between-two-sets-of-vectors/ def get_sq_distances(X, Y): a = np.sum(np.square(X),axis=1,keepdims

Euclidean Distances between rows of two data frames in R

做~自己de王妃 提交于 2021-02-17 03:29:36
问题 Calculating Euclidean Distances in R is easy. A good example can be found HERE. The vectorised form is: sqrt((known_data[, 1] - unknown_data[, 1])^2 + (known_data[, 2] - unknown_data[, 2])^2) What would be the fastest, most efficient way to get Euclidean Distances for each row of one data frame with all rows of another data frame? A particular function from apply() family? Thanks! 回答1: Maybe you can try outer + dist like below outer( 1:nrow(known_data), 1:nrow(unknown_data), FUN = Vectorize

Find all shortest Euclidean distances between two groups of point coordinates

左心房为你撑大大i 提交于 2021-02-11 13:15:05
问题 I have a Pandas DataFrame, where columns X1, Y1 have point coordinates for the first group of coordinates and columns X2, Y2 have point coordinates for the second group of coordinates. Both groups are independent of each other. It is just happen to be they are in the same dataframe. Example: X1,Y1,X2,Y2 41246.438,0.49,38791.673,0.49 41304.5,0.491,38921.557,0.491 41392.062,0.492,39037.135,0.492 41515.5,0.493,39199.972,0.493 41636.062,0.494,39346.561,0.494 41795.188,0.495,39477.63,0.495 42027

Find all shortest Euclidean distances between two groups of point coordinates

旧巷老猫 提交于 2021-02-11 13:12:20
问题 I have a Pandas DataFrame, where columns X1, Y1 have point coordinates for the first group of coordinates and columns X2, Y2 have point coordinates for the second group of coordinates. Both groups are independent of each other. It is just happen to be they are in the same dataframe. Example: X1,Y1,X2,Y2 41246.438,0.49,38791.673,0.49 41304.5,0.491,38921.557,0.491 41392.062,0.492,39037.135,0.492 41515.5,0.493,39199.972,0.493 41636.062,0.494,39346.561,0.494 41795.188,0.495,39477.63,0.495 42027

MATLAB: Computing euclidean distance in an efficient way?

删除回忆录丶 提交于 2021-02-11 12:13:24
问题 What I am currently doing is computing the euclidean distance between all elements in a vector (the elements are pixel locations in a 2D image) to see if the elements are close to each other. I create a reference vector that takes on the value of each index within the vector incrementally. The euclidean distance between the reference vector and all the elements in the pixel location vector is computed using the MATLAB function "pdist2" and the result is applied to some conditions; however,

Function to calculate Euclidean distance in R

依然范特西╮ 提交于 2021-02-10 14:19:14
问题 I am trying to implement KNN classifier in R from scratch on iris data set and as a part of this i have written a function to calculate the Euclidean distance. Here is my code. known_data <- iris[1:15,c("Sepal.Length", "Petal.Length", "Class")] unknown_data <- iris[16,c("Sepal.Length", "Petal.Length")] # euclidean distance euclidean_dist <- function(k,unk) { distance <- 0 for(i in 1:nrow(k)) distance[i] <- sqrt((k[,1][i] - unk[,1][i])^2 + (k[,2][i] - unk[,2][i])^2) return(distance) }

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

橙三吉。 提交于 2021-02-07 06:00:22
问题 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 at most 10^5 points in the set and 10^5 queries. All the coordinates for points are in range from 0 to 10^5. I am wondering if there is a way to store the set of points such that we can answer the queries in O(log n) or O(log^2 n) if necessary.

Calculate Euclidean Distance between all the elements in a list of lists python

别说谁变了你拦得住时间么 提交于 2021-01-29 22:05:51
问题 I have a list of lists. I want to find the euclidean distance between all the pairs and itself and create a 2D numpy array. The distance between itself will have 0 in the place and the value when the pairs are different. Example of List of Lists: [[0, 42908],[1, 3],[1, 69],[1, 11],[0, 1379963888],[0, 1309937401],[0, 1],[0, 3],[0, 3],[0, 77]] The result I want is 0 1 2 3 4 5 6 7 8 0 0 x x x x x x x x 1 0 x x x x x x x 2 0 x x x x x x 3 0 x x x x x 4 ................. 5 ................. 6 ....

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

二次信任 提交于 2020-12-28 07:45:35
问题 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 distance between point O and line segments as shown in the shown figure implemented in line of codes. The code I can really understand is either pseudo-code or Python. CODE: I tried to solve the problem with this code, unfortunately, it does not work properly. def dist(A, B, O): A_ = complex(*A)

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

独自空忆成欢 提交于 2020-12-28 07:42:15
问题 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 distance between point O and line segments as shown in the shown figure implemented in line of codes. The code I can really understand is either pseudo-code or Python. CODE: I tried to solve the problem with this code, unfortunately, it does not work properly. def dist(A, B, O): A_ = complex(*A)