RE: irritating little problem
- To: mathgroup at smc.vnet.net
- Subject: [mg32931] RE: [mg32906] irritating little problem
- From: "David Park" <djmp at earthlink.net>
- Date: Wed, 20 Feb 2002 01:26:10 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Peter,
Here is one solution. Perhaps you will get a better one. This gives you a
list of element values and all the positions of that element value.
IdenticalPositions[list_] :=
(With[{lst = Transpose[#1]}, {lst[[1,1]], Sort[lst[[2]]]}] & ) /@
Split[Sort[Transpose[{list, Range[Length[list]]}],
OrderedQ[{#1[[1]], #2[[1]]}] & ], #1[[1]] === #2[[1]] & ]
list = Array[Random[Integer, {0, 9}] &, 20]
{4, 5, 6, 6, 4, 7, 2, 4, 2, 5, 1, 6, 4, 1, 6, 8, 2, 4, 2, 5}
IdenticalPositions[list]
{{1, {11, 14}}, {2, {7, 9, 17, 19}}, {4, {1, 5, 8, 13, 18}}, {5, {2, 10,
20}}, {6, {3, 4, 12, 15}}, {7, {6}}, {8, {16}}}
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
> From: KIMIC Weijnitz Peter [mailto:micweij at eka.ericsson.se]
To: mathgroup at smc.vnet.net
>
> I have a simple vector
> and I want to find the position of elements that are equal.
>
> I.e I want to test the vector and find all cases of similar elements.
>
> Brute force is not what I want, it can be a long vector.
> Best regards
> Petr W
>