MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: irritating little problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32938] Re: [mg32906] irritating little problem
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Wed, 20 Feb 2002 01:26:20 -0500 (EST)
  • References: <200202190729.CAA18757@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

First, you must look at those elements that are appear more than once, and
then find their positions. A possibility - which I don't think is "brute
force" - is as follows (as an example, I take a vector of digits, but the
method works in general):

In[1]:=
a = Table[Random[Integer, {0, 9}], {20}]
Out[1]=
{5, 4, 9, 1, 1, 8, 5, 0, 9, 5, 5, 4, 1, 3, 6, 5, 9, 6, 0,
  8}

In[2]:=
<< Statistics`DataManipulation`

In[3]:=
b = Select[Frequencies[a], #[[1]] > 1 & ]
Out[3]=
{{2, 0}, {3, 1}, {2, 4}, {5, 5}, {2, 6}, {2, 8}, {3, 9}}

In[4]:=
({#[[2]], Flatten[Position[a, #[[2]]]]} & ) /@ b
Out[4]=
{{0, {8, 19}}, {1, {4, 5, 13}}, {4, {2, 12}},
  {5, {1, 7, 10, 11, 16}}, {6, {15, 18}}, {8, {6, 20}},
  {9, {3, 9, 17}}}

The last output says digit 0 appears in positions {8, 19}, digit 1 appears
in positions {4, 5, 13}, etc.

Tomas Garza
Mexico City

----- Original Message -----
From: "KIMIC Weijnitz Peter" <micweij at eka.ericsson.se>
To: mathgroup at smc.vnet.net
Subject: [mg32938] [mg32906] irritating little problem


> 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
>



  • Prev by Date: Re: irritating little problem
  • Next by Date: Numerical Differentiation using Fourier Transform
  • Previous by thread: irritating little problem
  • Next by thread: Re: irritating little problem