Re: Re: Pick function
- To: mathgroup at smc.vnet.net
- Subject: [mg62953] Re: [mg62928] Re: [mg62906] Pick function
- From: "Oyvind Tafjord" <tafjord at wolfram.com>
- Date: Fri, 9 Dec 2005 05:10:34 -0500 (EST)
- References: <200512080504.AAA11713@smc.vnet.net> <200512080836.DAA18265@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
----- 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
- References:
- Pick function
- From: Zdenek Buk <zdenek@buk.cz>
- Re: Pick function
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Pick function