Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Euclidean distance of all pairwise combinations (redundants)
Replies: 7   Last Post: Nov 18, 2012 4:02 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bob Hanlon

Posts: 890
Registered: 10/29/11
Re: Euclidean distance of all pairwise combinations (redundants)
Posted: Nov 15, 2012 4:05 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Left one off

Outer[EuclideanDistance[##] &, 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 12:01 PM, Bob Hanlon <hanlonr357@gmail.com> wrote:
> 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 b=
etween 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 examp=
le, 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 ret=
ained in the results. I have been using this code just to play with data bu=
t 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 in=

cluding redundants and self references?
>>
>>





Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.