euclidean-distance

Calculating Euclidean distance of pairs of 3D points in matlab

谁都会走 提交于 2019-12-02 01:32:07
问题 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 points. ( i , j ) in result array returns the distance between (ai,bi,ci) and (aj,bj,cj) . Is it possible to write a code in matlab without loop ? 回答1: The challenge of your problem is to make a N*N matrix and the result should return in this matrix without using loops. I overcome this challenge by

Computing Euclidean distances between subsequent positions

▼魔方 西西 提交于 2019-12-01 23:05:14
I have large data frames consisting of pairs of X and Y coordinates, and wish to calculate the Euclidean distances between consecutive coordinates (minimal size is around 2000 pairs of coordinates). Thus, I want to calculate the distance from row 1 to 2, row 2 to 3, row 3 to 4, etc. This question nicely shows how to calculate the Euclidean distance between the first and last point for track data, but my data are closer to: dff <- structure(list(A = c(0L, 0L, 0L, 0L, 0L, 0L), T = 0:5, X = c(668L, 670L, 672L, 674L, 676L, 678L), Y = c(259L, 259L, 259L, 259L, 259L, 260L), V = c(NA, 0, 0, 0, 0, 0))

Computing Euclidean distances between subsequent positions

被刻印的时光 ゝ 提交于 2019-12-01 22:20:51
问题 I have large data frames consisting of pairs of X and Y coordinates, and wish to calculate the Euclidean distances between consecutive coordinates (minimal size is around 2000 pairs of coordinates). Thus, I want to calculate the distance from row 1 to 2, row 2 to 3, row 3 to 4, etc. This question nicely shows how to calculate the Euclidean distance between the first and last point for track data, but my data are closer to: dff <- structure(list(A = c(0L, 0L, 0L, 0L, 0L, 0L), T = 0:5, X = c

Calculating Euclidean distance of pairs of 3D points in matlab

时间秒杀一切 提交于 2019-12-01 21:08:06
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 points. ( i , j ) in result array returns the distance between (ai,bi,ci) and (aj,bj,cj) . Is it possible to write a code in matlab without loop ? The challenge of your problem is to make a N*N matrix and the result should return in this matrix without using loops. I overcome this challenge by giving suitable dimension to Bsxfun function. By default X and ReshapedX should have the same dimensions when we

Wrong Euclidean distance H2O calculations R

元气小坏坏 提交于 2019-12-01 19:43:29
I am using H2O with R to calculate the euclidean distance between 2 data.frames: set.seed(121) #create the data df1<-data.frame(matrix(rnorm(1000),ncol=10)) df2<-data.frame(matrix(rnorm(300),ncol=10)) #init h2o h2o.init() #transform to h2o df1.h<-as.h2o(df1) df2.h<-as.h2o(df2) if I use normal calculations, i.e. the first row: distance1<-sqrt(sum((df1[1,]-df2[1,])^2)) And If I use the H2O library: distance.h2o<-h2o.distance(df1.h[1,],df2.h[1,],"l2") print(distance1) print(distance.h2o) The distance1 and distance.h2o are not the same. Does anybody knows why? Thanks!! It seems as if h2o.distance

How to calculate euclidean distance between pair of rows of a numpy array

我是研究僧i 提交于 2019-12-01 19:22:39
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 each pair of rows. from scipy.spatial import distance for i in range(0,a.shape[0]): d = [np.sqrt(np.sum((a[i]-a[j])**2)) for j in range(i+1,a.shape[0])] print(d) [1.4142135623730951, 0.0, 1.4142135623730951] [1.4142135623730951, 2.0] [1.4142135623730951] [] Is there any better pythonic way to do this since i have to run this code on a huge numpy array? And for completeness, einsum is often referenced for distance calculations. a = np

trying to draw circles based on distance between points

落花浮王杯 提交于 2019-12-01 17:19:26
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) distance <- spDistsN1(xy, xy[1, ]) plot(0,0, xlim = c(-100, 100), ylim = c(-100, 100), type = "n") points(data.frame(xy)) points(xy[1, 1], xy[1, 2], pch = 16) draw.circle(xy[1, 1], xy[1, 2], radius = distance) The above code does the following: Create 10 random points and choose one (first) point that would serve as an "anchor". Calculate distance from anchor to all other points. This will be our

trying to draw circles based on distance between points

我怕爱的太早我们不能终老 提交于 2019-12-01 16:33:45
问题 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) distance <- spDistsN1(xy, xy[1, ]) plot(0,0, xlim = c(-100, 100), ylim = c(-100, 100), type = "n") points(data.frame(xy)) points(xy[1, 1], xy[1, 2], pch = 16) draw.circle(xy[1, 1], xy[1, 2], radius = distance) The above code does the following: Create 10 random points and choose one (first) point

MATLAB - efficient way of computing distances between points in a graph/network using the adjacency matrix and coordinates

狂风中的少年 提交于 2019-12-01 12:32:41
I have the network representation in a 2D coordinate space. I have an adjacency matrix Adj (which is sparse) and a coordinate matrix with the x,y values of all the points/nodes/vertices in the graph which are drawn. I would like to compute as efficiently as possible the distance between these points. I would like to avoid cycling through the entries in the matrix and computing the pairwise distances one by one. [n, d] = size(coordinate); assert(d == 2); resi = sparse(Adj * diag(1:n)); resj = sparse(diag(1:n) * Adj); res = sparse(zeros(n)); f = find(Adj) res(f) = sqrt((coordinate(resi(f), 1) -

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

╄→гoц情女王★ 提交于 2019-12-01 06:00:58
This question already has an answer here: Efficient distance calculation between N points and a reference in numpy/scipy 6 answers Minimum Euclidean distance between points in two different Numpy arrays, not within 5 answers 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 i th point of mx2 matrix to j th point of nx2 matrix. I simply call the command pdist2(M,N) . I am looking for an alternative to this in python. I can of