Re: problem with Pick

*To*: mathgroup at smc.vnet.net*Subject*: [mg78221] Re: [mg78194] problem with Pick*From*: Oyvind Tafjord <tafjord at wolfram.com>*Date*: Tue, 26 Jun 2007 04:30:10 -0400 (EDT)*References*: <acbec1a40706230431p4f1db9a9i4320680dda027396@mail.gmail.com> <200706251106.HAA05048@smc.vnet.net> <467FE85C.6030700@wolfram.com> <acbec1a40706251652h78eedc03o95629f4a0e732ad1@mail.gmail.com>

Chris Chiasson wrote: > On 6/25/07, Oyvind Tafjord <tafjord at wolfram.com> wrote: >> In this case, sel={{},{1}}. sel[[]] matches patt, and so list[[]] is >> picked out. >> >> This behavior, in which all of list gets picked, does produce a fair >> amount >> of confusion, unfortunately. It often shows up in connection with Except: >> >> In[1]:= Pick[{a, b, c}, {1, 2, 3}, Except[2]] >> Out[1]= {a, b, c} >> >> In[2]:= Pick[{a, b, c}, {1, 2, 3}, Except[2, _Integer]] >> Out[2]= {a, c} > > Thank you for the reply. > > You seem to be implying that the above behavior is intended, even > though it violates the documentation. I believe it is unintended, due > to the following output, which seems to indicate that the matches are > supposed to be checked on the first level: > > In[1]:= Pick[{a,b,c},SparseArray@{1,2,3},Except[2]] > Pick[{a,b,c},{1,2,3},Except[2]] > > Out[1]= {a,c} > > Out[2]= {a,b,c} > > If I am wrong, then this SparseArray behavior is a bug, the > documentation is wrong, and I suggest that an optional level argument > be added to Pick. > In what way does this behavior violate the documentation? It uses the statement you quoted: Pick[list,sel,patt] picks out those list[[i1,i2,...]] for which sel[[i1,i2,...]] matches patt. with the 0-length version of i1,i2,... I agree this is often what you don't want though. The SparseArray case is treated differently, in this case only the individual elements are treated as "selectors", for optimization and usefulness. This could be explained better in the documentation. E.g., compare In[20]:= Pick[{{a, b, c}, {d, e, f}}, SparseArray@{{3, 4, 5}, {1, 2, 3}}, 4] Out[20]= {{b}, {}} In[21]:= Pick[{{a, b, c}, {d, e, f}}, SparseArray@{{3, 4, 5}, {1, 2, 3}}, {3, 4, 5}] Out[21]= {{}, {}} In[22]:= Pick[{{a, b, c}, {d, e, f}}, {{3, 4, 5}, {1, 2, 3}}, {3, 4, 5}] Out[22]= {{a, b, c}, {}} Oyvind Tafjord Wolfram Research

**References**:**problem with Pick***From:*"Chris Chiasson" <chris@chiasson.name>