MathGroup Archive 2011

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

Search the Archive

Re: Following position change in different vectors

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117522] Re: Following position change in different vectors
  • From: István Zachar <zac at freemail.hu>
  • Date: Mon, 21 Mar 2011 06:17:44 -0500 (EST)
  • References: <im4iqj$d1b$1@smc.vnet.net>

Dear Tam=E1s,

If I understand correctly, this might help:

In[99]:= n = 10;
v1 = RandomSample[Range[20], n]

Out[100]= {6, 3, 14, 18, 19, 11, 12, 15, 9, 2}

In[101]:= v2 = Map[a, v1]

Out[101]= {a[6], a[3], a[14], a[18], a[19], a[11], a[12], a[15], a[9],
a[2]}

In[102]:= order = Ordering[v1]

Out[102]= {10, 2, 1, 9, 6, 7, 3, 8, 4, 5}

In[103]:= Sort[v1]

Out[103]= {2, 3, 6, 9, 11, 12, 14, 15, 18, 19}

In[104]:= Part[v2, order]

Out[104]= {a[2], a[3], a[6], a[9], a[11], a[12], a[14], a[15], a[18],
a[19]}


Note that function 'a' can be anything, the sorting of v2 solely
depends on the ordering of v1!

Istv=E1n



On Mar 20, 10:53 am, Lengyel Tamas <lt... at hszk.bme.hu> wrote:
> Dear Mathworld Users,
>
> Sorry for asking your help again, I hope I'm not spamming too much.
> My problem is the following:
>
> 1) I have 2 vectors with equal length. The positions of the first vector
> correspond to the second vector. So the first element of v2 is calculated
> from the first element of v1, etc.
>
> 2) I wish to sort the first vector in ascending magnitude using Sort[v1].
> Naturally the positions of v1's elements change.
>
> What I want is the same change of position in v2's positions.
>
> (So e.g. if v1's sixth element moves after Sort to  the first position,
> I'd like v2's same position element to follow suit)
>
> Thank you for your help in advance.
>
> Tamas



  • Prev by Date: Re: Following position change in different vectors
  • Next by Date: Re: Vs. 2.2 Notebooks in vs. 7.0?
  • Previous by thread: Re: Following position change in different vectors
  • Next by thread: Re: Following position change in different vectors