MathGroup Archive 2006

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

Search the Archive

Re: sparsearray and random

  • To: mathgroup at smc.vnet.net
  • Subject: [mg71454] Re: sparsearray and random
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sun, 19 Nov 2006 01:10:09 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <ejmlhi$gp1$1@smc.vnet.net>

Arkadiusz.Majka at gmail.com wrote:
> Hi,
> 
> Why this:
> 
> a = Random[Integer, {3, 7}]
> Normal[SparseArray[(i_ /; 3 â?¤ i â?¤ a) -> p, 10]]
> 
> is not the same as this:
> 
> Normal[SparseArray[(i_ /; 3 â?¤ i â?¤Random[Integer, {3, 7}] ) -> p,
> 10]]

Could you explain what you mean by "not the same"? For instance, in the 
following expressions, only In[4] is not the same as the three other 
inputs in term of behavior: In[4] checks i against a new random number 
every time, whereas the other expressions keep the same upper bound 
during the whole evaluation process.

In[1]:=
a = Random[Integer, {3, 7}]
Normal[SparseArray[i_ /; 3 <= i <= a -> p, 10]]

Out[1]=
6

Out[2]=
{0, 0, p, p, p, p, 0, 0, 0, 0}

In[3]:=
Normal[SparseArray[i_ /; 3 <= i <= Random[Integer, {3, 7}] -> p, 10]]

Out[3]=
{0, 0, p, p, p, 0, 0, 0, 0, 0}

In[4]:=
a := Random[Integer, {3, 7}]
Normal[SparseArray[i_ /; 3 <= i <= Evaluate[a] -> p, 10]]

Out[5]=
{0, 0, p, p, p, 0, p, 0, 0, 0}

In[6]:=
Normal[SparseArray[i_ /; 3 <= i <= Evaluate[Random[Integer, {3, 7}]] -> 
p, 10]]

Out[6]=
{0, 0, p, p, p, p, 0, 0, 0, 0}

Regards,
Jean-Marc


  • Prev by Date: Re: Limit of Infinitely Nested Expression
  • Next by Date: Re: RE:Need Help: Can not use Ticks under PolarPlot
  • Previous by thread: Re: sparsearray and random
  • Next by thread: Limit of Infinitely Nested Expression