javascript,coordinates,euclidean-distance

I guess your problem is figuring out how to make this work: Robot.prototype.seDeplacer = function() { var point1X = (this.position(Math.random() * this.maxSpeed+1); var point1Y = (this.position(Math.random() * this.maxSpeed)+1; console.log("je suis" + point1X + point1Y); }; Now, assuming that position is an array of x and y coordinates, then if you...

One way is to generate a Cartesian product of all points, effectively producing all possible pairs of points, and then compute euclidean distances between them. Then you will have just a list of distance numbers, so the rest is trivial: var pointWithIndex = points.Select((x, i) => new { Point =...

python,numpy,scipy,euclidean-distance,cosine-similarity

You can use scipy.spatial.distance.squareform to convert between a full m x n distance matrix and the upper triangle: import numpy as np from scipy.spatial import distance m = 100 n = 200 X = np.random.randn(m, n) d = distance.pdist(X, metric='jaccard') print(d.shape) # (4950,) D = distance.squareform(d) print D.shape # (100,...

matlab,for-loop,vector,built-in,euclidean-distance

Use pdist2. Assuming (from your code) that your vectors are columns, transposition is needed because pdist2 works with rows: [cmin, match_col] = min(pdist2(vectors.', input_vector.' ,'euclidean')); It can also be done with bsxfun (in this case it's easier to work directly with columns): [cmin, match_col] = min(sum(bsxfun(@minus, vectors, input_vector).^2)); cmin =...

python,optimization,numpy,matplotlib,euclidean-distance

You can use matplotlib to do the drawing, here is an example: I create a RendererAgg and a ndarray share the same memory with it. Then create the Line2D artist, and call the draw() method on the RendererAgg object. import numpy as np from matplotlib.backends.backend_agg import RendererAgg w, h =...

python,numpy,intersection,euclidean-distance,line-intersection

Basic algorithm: pretend that you have lines, so oriented that A lies to the left of B. Find closest point as normal. If the point is between A and B, you're done. If it's to the left of A, the closest point is A. If the point is to the...

r,csv,hierarchical-clustering,euclidean-distance,conceptual

All answers were important, but @Ben video recommendation and @Samuel Tan advice on breaking the customers into grids, I found a good way to handle it. The video gave me a lot of insights about "noisy" variables in hierarchical clustering, and the grid recommendation helped me think on what the...

matlab,machine-learning,time-series,euclidean-distance

For the first question you could try tmp = repmat(A,1,b); C = reshape([tmp zeros(1,b)],a,b); C = C(1:(a-b+1),:); Besides, pdist2 is very slow in comparison to this very nice solution: Efficiently compute pairwise squared Euclidean distance in Matlab ...

distance,shape,similarity,euclidean-distance

What distance function to use depends on your concrete task. I guess cosine similarity may be what you want....

math,vector,dimension,euclidean-distance

The euclidian distance calculus is independent of dimensions. In your case, the euclidian distance between a and b can be written as: d(a,b) = sqrt(sum_{i=1}^{4} (a[i] - b[i])^2). Or, more specifically: d(a,b) = sqrt( (a1-b1)^2 + (a2-b2)^2 + (a3-b3)^2 + (a4-b4)^2 )....

python,python-imaging-library,pixels,pillow,euclidean-distance

Try this: colors = im.getdata() #all pixel values # initialize lists for dark and light pixels darkList=[] lightList=[] # set counter for dark and light pixels dark = 0 light = 0 for item in colors: # iterate over each tuple if sqrt((item[0]-255)**2 + (item[1]-255)**2) < 128: # See if...

matlab,matrix,euclidean-distance

It does not work because the dist function when called with two arguments works like this: Z = dist(W,P) takes an SxR weight matrix and RxQ input matrix and returns the SxQ matrix of distances between W's rows and P's columns. dist(P',P) returns the same result as dist(P). That is,...

matlab,matrix,alignment,time-series,euclidean-distance

I think this question really belongs on Math.StackExchange, but I will do my best to answer it here. The short answer is that the Euclidean distance cannot be applied in this case and you will need to define your own notion of distance. This may or may not actually be...

java,distance,getter-setter,coordinate,euclidean-distance

As @Dude pointed out in the comments, you should write a method: public double distanceTo(Point3d p) { return Math.sqrt(Math.pow(x - p.getxCoord(), 2) + Math.pow(y - p.getyCoord(), 2) + Math.pow(z - p.getzCoord(), 2)); } Then if you want to get the distance between 2 points you just call: myPoint.distanceTo(myOtherPoint); //or if...

text,data-mining,information-retrieval,euclidean-distance,cosine-similarity

If your data is normalized to unit length, then it is very easy to prove that Euclidean(A,B) = 2 - Cos(A,B) This does hold if ||A||=||B||=1. It does not hold in the general case, and it depends on the exact order in which you perform your normalization steps. I.e. if...

python,arrays,numpy,euclidean-distance

You can do something like this: >>> import numpy as np >>> from itertools import combinations >>> A = np.array([[1, 2, 3], [4, 5, 6], [10, 20, 30]]) >>> [np.linalg.norm(a-b) for a, b in combinations(A, 2)] [5.196152422706632, 33.674916480965472, 28.930952282978865] ...

python,opencv,numpy,pixel,euclidean-distance

You can get an array of distance from the center using the following lines (which is an example, there are a lot of ways to do this): import numpy as np myArr = np.array([[0,1,2], [3,4,5]]) nx, ny = myArr.shape x = np.arange(nx) - (nx-1)/2. # x an y so they...

python,numpy,vector,euclidean-distance

You could use cdist from scipy.spatial.distance to efficiently get the euclidean distances and then use np.argmin to get the indices corresponding to minimum values and use those to index into B for the final output. Here's the implementation - import numpy as np from scipy.spatial.distance import cdist C = B[np.argmin(cdist(A,B),1)]...

python,arrays,distance,euclidean-distance

Another solution to #1: print(S.to_string()) # print the entire table and to get distances # assumes Python 3 from functools import partial def dist(row, col1, col2): return sum((c2 - c1)**2 for c1,c2 in zip(row[col1], row[col2])) ** 0.5 # compose a function (name the columns it applies to) s_dist = partial(dist,...

c++,parallel-processing,geometry,lines,euclidean-distance

The distance between two parallel lines will be the distance between the first (infinite) line and any point (say, P3) on the second line. Since you are working with coordinates, it's more convenient to use the vector representation of the formula than to try to express the line as an...