Pick function
- To: mathgroup at smc.vnet.net
- Subject: [mg62906] Pick function
- From: Zdenek Buk <zdenek at buk.cz>
- Date: Thu, 8 Dec 2005 00:04:56 -0500 (EST)
- Organization: Czech Technical University
- Sender: owner-wri-mathgroup at wolfram.com
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}
Out[1]:=
{1, a -> b, x, c -> 1, d -> e + f, g + h}
In[2]:=
l2=Table[i,{i,Length[l]}]
Out[2]=
{1,2,3,4,5,6}
Now try to select the "Rules":
-----------------------------
In[3]:=
Cases[l,x:(_->_)]
Out[3]=
{a->b,c->1,d->e+f}
OK, this is what I expected.
but...
Try to use the Pick function:
----------------------------
In[4]:=
sel1=Pick[l,l,_->_]
Out[4]=
{a->b,c->1,d->e+f,0}
In[5]:=
sel2=Pick[l2,l,_->_]
Out[5]=
{2,4,5}
As you can see, the the first command returned 4 items, but the second
command returned only 3 items (as expected).
I really don't understand why there is the last "0" value in "sel1" list.
I expected, that "Pick[l,l,_->_]" command should return:
"{a->b,c->1,d->e+f}".
Is here somebody who can explain this strange behavior for me, please?
Zdenek Buk
- Follow-Ups:
- Re: Pick function
- From: Andrzej Kozlowski <akoz@mimuw.edu.pl>
- Re: Pick function