Re: Working in Modules

*To*: mathgroup at smc.vnet.net*Subject*: [mg15954] Re: Working in Modules*From*: juan antonio gonzalez castro <jagonzal at students.uiuc.edu>*Date*: Wed, 17 Feb 1999 23:34:13 -0500*Organization*: University of Illinois at Urbana-Champaign*References*: <7a2c0d$1ul@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

The difference in your outputs is because while Module init includes Partition[s,n] as last command, Module init1 doesn't. Partition[s,n] splits the list s into a list of n lists, i.e., it partitions the set s of nxn elements into n lists with n elements each. NOTE THAT IN init PARTITION IS DONE ON s, NOT ON THE TABLE THAT THE TRANSFORMATION S /. {0->-1}, GENERATES, which is the table you get as output from init1. Now, if what you need is to partition the latter you can rewrite your module as: init2[n_Integer]:=Module[ {s=Table[Random[Integer],{n n}]}, Partition[s/.{0->-1},n] the output of init2 should be a list of n lists with n elements each, in which zeros have been replaced by -1. I hope this solves your puzzle. _______________________________________________________________________ Juan A. Gonzalez-Castro, On 12 Feb 1999, Dr D McK Paul wrote: > This is my third attempt to post this question. No idea why it doesnt > work. I'm not an expert in Mathematica and would appreciate comments on > why init1 returns a list with all zeros replaced by -1, but init does > not. Its probably very simple but its confused me. > > Don > > init[n_Integer]:=Module[ > {s=Table[Random[Integer],{n n}]}, > s/.{0->-1}; > Partition[s,n] > ] > > init1[n_Integer]:=Module[ > {s=Table[Random[Integer],{n n}]}, > s/.{0->-1} > ] > > > -- > > Prof. Don McKenzie Paul tel. (1203) 523603 Department of > Physics fax. (1203) 692016 University of Warwick > email phrje at csv.warwick.ac.uk COVENTRY CV4 7AL > UK > -- > ****************************************************** Professor Don > McKenzie Paul > Department of Physics > University of Warwick > > >