MathGroup Archive 2007

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

Search the Archive

Re: RandomChoice does not accept null weights

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83412] Re: RandomChoice does not accept null weights
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Tue, 20 Nov 2007 03:43:11 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fhrs9r$5qo$1@smc.vnet.net>

Szabolcs Horv=C3=A1t wrote:

> Szabolcs Horv=C3=A1t wrote:
>> ... or Pick[]ing out those elements whose
>> weight is not 0 before passing them to RandomChoice[].
>
> Pick[] caused a lot confusion here ... so some people may find the
> following information useful.
>
> Consider the this example:
>
> In[1]:= Pick[{a, b, c}, {0, 1, 2}, Except[0]]
> Out[1]= {a, b, c}
>
> I expected the result {b, c}.  So why is it {a, b, c}?  Here is the
> explanation:
>
> http://groups.google.com/group/comp.soft-sys.math.mathematica/browse_th=
read/thread/b011242fd0f042a1/4930d9a0540d808f
>
> IMO this example should be included under "possible issues" in Pick's
> documentation.

I second that.

Just for the sake of completeness with my previous post about
w0RandomChoice, the following expressions build rules in the format
expected by RandomChoice.

In[1]:= Rule[Select[{0, 1, 2}, Positive],
  Pick[{a, b, c}, Unitize@{0, 1, 2}, 1]]

Out[1]= {1, 2} -> {b, c}

In[2]:= Rule[Select[{0, 1, 2}, Positive],
  Pick[{a, b, c}, {0, 1, 2}, Except[0, _Integer]]]

Out[2]= {1, 2} -> {b, c}

Regards,
--
Jean-Marc



  • Prev by Date: Re: Mathematica question : Stepsize control
  • Next by Date: Re: Mapping Functions That Take More Than One Argument
  • Previous by thread: RandomChoice does not accept null weights
  • Next by thread: Re: RandomChoice does not accept null weights