Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: Dont Understand

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15896] Re: [mg15857] Dont Understand
  • From: BobHanlon at aol.com
  • Date: Wed, 17 Feb 1999 23:33:42 -0500
  • Sender: owner-wri-mathgroup at wolfram.com

In a message dated 2/12/99 8:38:01 PM, phrje at csv.warwick.ac.uk writes:

>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}
>                    ]
>

Don,

In the definition of Init you did not "save" the results of the substitution
and, consequently, the partition was applied to the originally defined value
of s.  Use any of these definitions:

init[n_Integer] := Module[
                    {s=Table[Random[Integer],{n n}]},
                    s = s/.{0->-1};
                    Partition[s,n]
                    ];

init[n_Integer] := Module[
                    {s=Table[Random[Integer],{n n}]},
                    Partition[s/.{0->-1}, n]
                    ];

init[n_Integer] := Partition[Table[Random[Integer], {n n}] /. {0->-1},n];


Bob Hanlon


  • Prev by Date: Help - Single Variable Calc
  • Next by Date: Mathematica Link for LabVIEW Now Available
  • Previous by thread: Re: Dont Understand
  • Next by thread: Re: Dont Understand