euclidean-distance

Euclidean distances (python3, sklearn): efficiently compute closest pairs and their corresponding distances

最后都变了- 提交于 2019-12-06 05:55:40
I'm given a 2-D numpy array X consisting of floating values and need to compute the euclidean distances between all pairs of rows, then compute the top k row indices with the smallest distances and return them (where k > 0). I'm testing with a small array and this is what I have so far... import numpy as np from sklearn.metrics.pairwise import euclidean_distances X_testing = np.asarray([[1,2,3.5],[4,1,2],[0,0,2],[3.4,1,5.6]]) test = euclidean_distances(X_testing, X_testing) print(test) The resulting printout is: [[ 0. 3.5 2.6925824 3.34215499] [ 3.5 0. 4.12310563 3.64965752] [ 2.6925824 4

Calculating a Voronoi diagram for planes in 3D

放肆的年华 提交于 2019-12-06 02:26:12
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 size of spheres but I couldn't find anything for polygons. In this image (sample planes in 3d) the parallelograms are 3D since they have a thickness, but in this case the thickness will be zero.! Voronoi cells are not parallelograms. You are confused here by the image you posted. Voronoi cell borders are parts of the hyperplanes that are separating the individual means. Check out this website

Distance matrix from two separate data frames

拈花ヽ惹草 提交于 2019-12-05 18:02:49
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) b <- c(5,4,3,2,1) c <- c(5,4,1,2,3) df1 <- data.frame(a,b,c) a2 <- c(2,7,1,2,3) b2 <- c(7,6,5,4,3) c2 <- c(1,2,3,4,5) df2 <- data.frame(a2,b2,c2) I would like to create a matrix with the distances of each row in df1 versus the rows of df2. So matrix[2,1] should be the euclidean distance between df1[2,] and df2[1,]. matrix[3,2] the distance between df[3,] and df2[2,], etc. Does anyone know how this

Numpy: find the euclidean distance between two 3-D arrays

故事扮演 提交于 2019-12-05 15:59:09
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 distance for each vector in A and B efficiently? I have tried for-loops but these are slow, and I'm working with 3-D arrays in the order of (>>2, >>2, 2). Ultimately I want a matrix of the form: C = [[d1, d2], [d3, d4]] Edit: I've tried the following loop, but the biggest issue with it is that loses the dimensions I want to keep. But the distances are correct. [numpy.sqrt((A[row, col][0] - B[row, col][0])**2 + (B[row, col][1]

How to calculate Euclidean length of a matrix without loops?

假如想象 提交于 2019-12-05 07:58:33
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 calculate the distance from the origin to the item. In a non vectorized form this is easy. distance = norm([x y z]); or distance = sqrt(x^2+y^2+z^2); However, in vectorized form its not so simple. When you pass a matrix to norm it no longer returns the Euclidean length. distance = norm(matrix); %doesn't work and distance = sqrt(x(:,1).*x(:,1)+y(:,2).*y(:,2)+z(:,3).*z(:,3)); %just seems messy Is there a

Pairwise Distance Calculation in c++

天涯浪子 提交于 2019-12-05 05:02:45
问题 I'm computing the potential energy of a large (~1e5) number of particles in c++. In order to do this, I'm running a double loop in which I calculate pairwise distances, and from those distance compute the total potential energy of the system. Below is the relevant piece of the code (it's not copy/paste ready, since data needs to be defined, and a few things are out of context; the method is still valid, and this is what I'm trying to show here): int colstart = 2; int colend = 4; double PE = 0

Calculate distance between two descriptors

你离开我真会死。 提交于 2019-12-04 21:36:17
I'm trying to calculate the distance (Euclidean or hamming) between two descriptors already calculated. The problem is I don't want to use a matcher, I just want to calculate the distance between two descriptors. I'm using OpenCV 2.4.9 and i have mine descriptors stored in a Mat type: Mat descriptors1; Mat descriptors2; and now i just want to calculate the distance (preferably the Hamming distance since I'm using binary descriptors) between row1 of descriptors1 and row1 of descriptors2 (for example). I have tried to use bitwise_xor() function but then I got not an effective way of doing the

R function to calculate nearest neighbor distance given [inconsistent] constraint?

笑着哭i 提交于 2019-12-04 19:11:51
I have data consisting of tree growth measurements (diameter and height) for trees at known X & Y coordinates. I'd like to determine the distance to each tree's nearest neighbor of equal or greater size . I've seen other SE questions asking about nearest neighbor calculations (e.g., see here , here , here , here , etc.), but none specify constraints on the nearest neighbor to be searched. Is there a function (or other work around) that would allow me to determine the distance of a point's nearest neighbor given that nearest point meets some criteria (e.g., must be equal to or greater in size

Computing net distance (Euclidean distance) in R

江枫思渺然 提交于 2019-12-04 18:30:46
I have asked about and receive great help for computing Euclidean distance in R before. Now, I need to compute the Euclidean distance from the first point relative to all the other points within the track data. Here is how my data looks like: dput(head(t1)) structure(list(A = c(0L, 0L, 0L, 0L, 0L, 0L), T = 0:5, X = c(668L, 668L, 668L, 668L, 668L, 668L), Y = c(259L, 259L, 259L, 259L, 259L, 259L), V = c(NA, 0, 0, 0, 0, 0)), .Names = c("A", "T", "X", "Y", "V"), row.names = c(NA, 6L), class = "data.frame") And SimonO101 was so great in giving me a code that will compute the Euclidean distance from

calculate Euclidean distance of two image in hsv color space in matlab

余生颓废 提交于 2019-12-04 13:46:55
i use the code below to calculate the Euclidean distance for two rgb images: Im1 = imread(filename1); Im1 = rgb2gray(Im1); hn1 = imhist(Im1)./numel(Im1); Im2 = imread(filename2); Im2 = rgb2gray(Im2); hn2 = imhist(Im2)./numel(Im2); f = norm(hn1-hn2); and it gives me the correct answer but now i want to use the code for two images in hsv color mode but it wont work on it cause all of the above code is in a 2d space while hsv is 1d is there any specific code for calculating Euclidean distance of two image in hsv color space? the images format are jpeg You need to create a histogram for each