MathGroup Archive 1999

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

Search the Archive

Re: Dont Understand


Don McKenzie Paul wrote:
> 
> 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}
>                     ]
> ...


Hi,

The modules always return the last statement. In "init1" it is the
result of "s/.{0->-1}", but in "init" the partitioning of your original
list "s"! 
You probably wanted to have the replaced "s" being partitioned:

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


Regards,
Harald

-- 
Harald Giese
Email: giese at dkrz.de
Phone: +49 (0)40 4123 5796; Fax: +49 (0)40 5605724
Institut fuer Meereskunde der Universitaet Hamburg
(Institute of Oceanography of the University of Hamburg)
Troplowitzstrasse 7, D-22529 Hamburg


  • Prev by Date: Re: 3D List Plots
  • Next by Date: Re: interpolatingfunction
  • Previous by thread: Re: Dont Understand
  • Next by thread: Re: Dont Understand