Mathematica 9 is now available
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

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


  • Prev by Date: Re: Questions on Apply function
  • Next by Date: Re: Questions on Apply function
  • Previous by thread: Re: General--tracing the solver
  • Next by thread: Re: Pick function