Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #12348 > unrolled thread

Re: Euclidean distance of all pairwise combinations (redundants)

Started byBob Hanlon <hanlonr357@gmail.com>
First post2012-11-15 09:05 +0000
Last post2012-11-15 09:05 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Euclidean distance of all pairwise combinations (redundants) Bob Hanlon <hanlonr357@gmail.com> - 2012-11-15 09:05 +0000

#12348 — Re: Euclidean distance of all pairwise combinations (redundants)

FromBob Hanlon <hanlonr357@gmail.com>
Date2012-11-15 09:05 +0000
SubjectRe: Euclidean distance of all pairwise combinations (redundants)
Message-ID<k82b87$7lh$1@smc.vnet.net>
You want to use Tuples rather than Subsets

list = {{1, 1}, {2, 2}, {3, 3}};

EuclideanDistance @@@ Tuples[list, 2]

{0, Sqrt[2], 2 Sqrt[2], Sqrt[2], 0, Sqrt[2], 2 Sqrt[2], Sqrt[2], 0}

Norm /@ Subtract @@@ Tuples[list, 2]

{0, Sqrt[2], 2 Sqrt[2], Sqrt[2], 0, Sqrt[2], 2 Sqrt[2], Sqrt[2], 0}

Norm[Subtract[##]] & @@@ Tuples[list, 2]

{0, Sqrt[2], 2 Sqrt[2], Sqrt[2], 0, Sqrt[2], 2 Sqrt[2], Sqrt[2], 0}

Norm[#[[1]] - #[[2]]] & /@ Tuples[list, 2]

{0, Sqrt[2], 2 Sqrt[2], Sqrt[2], 0, Sqrt[2], 2 Sqrt[2], Sqrt[2], 0}

Outer[Norm[#1 - #2] &, list, list, 1] // Flatten

{0, Sqrt[2], 2 Sqrt[2], Sqrt[2], 0, Sqrt[2], 2 Sqrt[2], Sqrt[2], 0}


Bob Hanlon


On Wed, Nov 14, 2012 at 1:29 AM, Jesse Pisel <jessepisel@gmail.com> wrote:
> I have been having a tough time trying to figure out how to include all red undant pairwise combinations in my results for the euclidean distance between a set of points. I have a set of points with xy coordinates and want the euclidean distance between each point including the point and itself. So if my points in xy space are list = {{1, 1}, {2, 2}, {3, 3}} for example, I want the distance from {1, 1} to {1, 1}, {1, 1} to {2, 2}, and {2, 2} to {3, 3} etc. for each point for a total of 9 distances all together. The EuclideanDistance function removes the redundant distances that I want retained in the results. I have been using this code just to play with data but would like to be able to expand up to 500+ points:
>
> list = {{1, 1}, {2, 2}, {3, 3}}
> EuclideanDistance @@@ Subsets[list, {2}]
>
> Any ideas on how to get the euclidean distance between all the points including redundants and self references?
>
>

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web