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: [mg15915] Re: Dont Understand
  • From: Harald Giese <giese at dkrz.de>
  • Date: Wed, 17 Feb 1999 23:33:52 -0500
  • Organization: Institut fuer Meereskunde, Universitaet Hamburg
  • References: <7a2bm8$1ts@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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