Re: Coding an inverse permutation
- To: mathgroup at smc.vnet.net
- Subject: [mg79105] Re: [mg79078] Coding an inverse permutation
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Thu, 19 Jul 2007 03:20:39 -0400 (EDT)
- References: <200707180652.CAA04270@smc.vnet.net>
On 18 Jul 2007, at 07:52, Diana wrote: > Folks, > > I have the following list: > > aa={1, 2, 5, 3, 4, 8, 9, 7, 11, 6, 13, 17, 10, 16, 19, 15, 14, 20, 21, > 23, 25, 12, 29, 31, 18, 22, > 37, 27, 26, 28, 33, 35, 32, 24, 41, 43, 30, 34, 47, 39, 38, 40, 45, > 49, 44, 36, 53, 55, 46, 52, > 59, 51, 50, 56, 57, 61, 62, 42, 67, 71, 48, 58, 65, 63, 64, 68, 69, > 73, 74, 54, 77, 79, 60, 76, > 83, 75, 80, 70, 81, 89, 85, 66, 95, 97, 72, 82, 91, 87} > > I want to figure out a clean way to code its inverse permutation. > > The inverse permutation list would start as follows: > > bb={1,2,4,5,3,10,8,6, ...} > > Since "3" is in position 4 of aa, position 3 of bb will be "4". > Since "5" is in position 3 of aa, position 5 of bb will be "3". > > Can someone give me a suggestion as to how to code this? > > Thanks, Diana > > Are you aware that your list isn't actually aa isn't a permutation of Range[Length[aa]]? Note that: Length[aa] 88 while the list ocntinas numbers larger than 88. Of course that does not affect the question - the important thing is that the elements of the list are distinct. The fastest way to find the inverse permutation (known to me) is: Range[Length[aa]][[Ordering[aa]]] {1, 2, 4, 5, 3, 10, 8, 6, 7, 13, 9, 22, 11, 17, 16, 14, 12, 25, 15, 18, 19, \ 26, 20, 34, 21, 29, 28, 30, 23, 37, 24, 33, 31, 38, 32, 46, 27, 41, 40, 42, \ 35, 58, 36, 45, 43, 49, 39, 61, 44, 53, 52, 50, 47, 70, 48, 54, 55, 62, 51, \ 73, 56, 57, 64, 65, 63, 82, 59, 66, 67, 78, 60, 85, 68, 69, 76, 74, 71, 72, \ 77, 79, 86, 75, 81, 88, 80, 87, 83, 84} Andrzej Kozlowski Wolfson College Oxford, UK
- References:
- Coding an inverse permutation
- From: Diana <diana.mecum@gmail.com>
- Coding an inverse permutation