Services & Resources / Wolfram Forums
MathGroup Archive
*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
  • Subject: [mg15896] Re: [mg15857] Dont Understand
  • From: BobHanlon at
  • Date: Wed, 17 Feb 1999 23:33:42 -0500
  • Sender: owner-wri-mathgroup at

In a message dated 2/12/99 8:38:01 PM, phrje at 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.
>                    {s=Table[Random[Integer],{n n}]},
>                    s/.{0->-1};
>                    Partition[s,n]
>                    ]
>                    {s=Table[Random[Integer],{n n}]},
>                    s/.{0->-1}
>                    ]


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

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