Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*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 2005

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

Search the Archive

Re: Re: Pick function


----- Original Message ----- 
From: "Andrzej Kozlowski" <akoz at mimuw.edu.pl>
To: mathgroup at smc.vnet.net
Subject: [mg62953] [mg62928] Re: [mg62906] Pick function


>
> On 8 Dec 2005, at 14:04, Zdenek Buk wrote:
>
>> Hi All,
>>
>> I have found a strange behavior of the "Pick" function.
>>
>> Testing data:
>> ------------
>> In[1]:=
>> l = {1, a -> b, x, c -> 1, d -> e + f, g + h}
>>
<snip>
>>
>> Try to use the Pick function:
>> ----------------------------
>>
>> In[4]:=
>> sel1=Pick[l,l,_->_]
>>
>> Out[4]=
>> {a->b,c->1,d->e+f,0}
>>
<snipped explanation>
>
> I am not completely sure whether this was entirely intended by the
> designer's of Pick and whether it would not be better if Pick had an
> option specifying the level at which the attempted matching should
> take place, but in any case, it shows that you have to use it carefully.
>
> Andrzej Kozlowski
>

Hi,

The explanation from Andrzej is correct, and I agree the behavior of Pick 
can be somewhat confusing at times. The key to remember is that the full 
nested structure of the selector (2nd) argument is used.

Having a level specification in Pick is probably not a bad idea, although 
it's really intended for use with selectors that have the exact structure of 
the result you want. So you could do something like

Pick[l, MatchQ[#, _ -> _] & /@ l]

although that wouldn't be very efficient for this particular case.

Oyvind Tafjord
Wolfram Research 


  • Prev by Date: Re: Skewness problem
  • Next by Date: Re: Pick function
  • Previous by thread: Re: Pick function
  • Next by thread: Re: Pick function