MathGroup Archive 2004

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

Search the Archive

Re: preserve neighborhood during random reordering

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

In article <btndvg$54$1 at>,
 Brent Pedersen <bpederse at> 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:


(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



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 

  • 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