MathGroup Archive 2004

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

Search the Archive

Re: preserve neighborhood during random reordering

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45530] Re: preserve neighborhood during random reordering
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Mon, 12 Jan 2004 02:15:40 -0500 (EST)
  • Organization: The University of Western Australia
  • References: <btndvg$54$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <btndvg$54$1 at smc.vnet.net>,
 Brent Pedersen <bpederse at nature.berkeley.edu> wrote:

> I have an n*n Table.  for example: 
> t1 = Table[Random[Integer, {0, 10}], {k}, {k}];

It would be better to include k in the function definition:

 t1[k_] := Table[Random[Real, {0, 10}], {k}, {k}]; 
 
> I want to rearrange the elements in t1 randomly (my actual t1 has real 
> data) such that for each entry t1[[i,j]] a random neighbor t1[[i+m,i+n]] 
> is chosen to replace it. Once that neighbor is chosen, it can still be 
> used to replace any of its other neighbors.  In the reshuffling an entry 
> can replace itself. Currently I have the size of the neighborhood fixed 
> at 9 cells (-1<= m,n <= 1) but eventually, I need to extend it to 25  
> (-2 <= m, n <= 2), 49, etc.

Here is one way to do this. Load the DiscreteMath stub:

  <<DiscreteMath`

(this automates the loading of andy of the DiscreteMath packages). 
Generate a random 5 x 5 matrix.

  mat = tab[5]

Now compute a random permutation of this matrix

  mat[[RandomPermutation[5],RandomPermutation[5]]]

Cheers,
Paul

-- 
Paul Abbott                                   Phone: +61 8 9380 2734
School of Physics, M013                         Fax: +61 8 9380 1014
The University of Western Australia      (CRICOS Provider No 00126G)         
35 Stirling Highway
Crawley WA 6009                      mailto:paul at physics.uwa.edu.au 
AUSTRALIA                            http://physics.uwa.edu.au/~paul


  • Prev by Date: Re: functions
  • Next by Date: Re: how to delete duplicate items in the same list
  • Previous by thread: preserve neighborhood during random reordering
  • Next by thread: Extracting elements of lists