PickCopy to clipboard.
✖
Pick
Details
- sel can be a nested list of any depth.
- Pick[list,sel,patt] picks out those list[[i1,i2,…]] for which sel[[i1,i2,…]] matches patt.
- Depending on the arrangement of elements matching patt in a nested list sel, Pick may return a ragged array.
- The heads in list and sel do not have to be List.
- Pick works with SparseArray objects.
- Parallelize[Pick[list,sel]] computes Pick[list,sel] in parallel on all subkernels. »
Examples
open allclose allBasic Examples (2)Summary of the most common use cases
Scope (4)Survey of the scope of standard use cases
Pick out elements wherever True appears in the "selector" list:
https://wolfram.com/xid/0mra6e-bqgtt0
Pick elements whose parts match a pattern:
https://wolfram.com/xid/0mra6e-mvbcyv
Use a SparseArray to select arguments:
https://wolfram.com/xid/0mra6e-1nby5h
https://wolfram.com/xid/0mra6e-q5bcor
Pick elements from a SparseArray:
https://wolfram.com/xid/0mra6e-kfvuf2
https://wolfram.com/xid/0mra6e-5g0if3
Generalizations & Extensions (3)Generalized and extended use cases
The data does not have to be a list:
https://wolfram.com/xid/0mra6e-mtkbcm
The selector argument need not be a list:
https://wolfram.com/xid/0mra6e-qi7wuu
Convert strings to a list of characters to pick only certain characters:
https://wolfram.com/xid/0mra6e-jzptym
Properties & Relations (2)Properties of the function, and connections to other functions
The comparison in Pick[list,sel,patt] is purely structural, with no regard to heads:
https://wolfram.com/xid/0mra6e-psnry0
f[b] is selected because the 3,1 part of sel matches the patt:
https://wolfram.com/xid/0mra6e-twezy6
The corresponding part of list, if it exists, will be picked, along with its heads:
https://wolfram.com/xid/0mra6e-n7pi8m
Note that the 2,1 part of sel also matches patt:
https://wolfram.com/xid/0mra6e-j9br2x
However, there is no corresponding part of list to be picked:
https://wolfram.com/xid/0mra6e-ftgtcd
Compute Pick in parallel:
https://wolfram.com/xid/0mra6e-ctrdfo
Possible Issues (4)Common pitfalls and unexpected behavior
The "selector" list has to have the same length and structure as the data:
https://wolfram.com/xid/0mra6e-k9j9u3
Atomic expressions are allowed in Pick:
https://wolfram.com/xid/0mra6e-9ngwr5
This is because all parts—including the empty part—are tested for matching:
https://wolfram.com/xid/0mra6e-rfcb2d
https://wolfram.com/xid/0mra6e-9reky7
If there is an atomic argument and it is not picked in its entirety, Sequence[] is returned:
https://wolfram.com/xid/0mra6e-28v58d
This applies equally to the second argument:
https://wolfram.com/xid/0mra6e-pds400
Using Except[c] in the third argument can lead to unexpected results:
https://wolfram.com/xid/0mra6e-2xfyd3
The whole expression is returned because the entire selector argument matches the pattern:
https://wolfram.com/xid/0mra6e-es2gd6
Use Except[c,p] to restrict the pattern to elements of the selector argument:
https://wolfram.com/xid/0mra6e-1kgosj
Using nonatomic expressions in the selector argument can lead to unexpected results:
https://wolfram.com/xid/0mra6e-89r0g
Applying the test beforehand so the list only contains True and False avoids the structure issue:
https://wolfram.com/xid/0mra6e-ycvai5
https://wolfram.com/xid/0mra6e-hrhljb
Wolfram Research (2004), Pick, Wolfram Language function, https://reference.wolfram.com/language/ref/Pick.html.
Text
Wolfram Research (2004), Pick, Wolfram Language function, https://reference.wolfram.com/language/ref/Pick.html.
Wolfram Research (2004), Pick, Wolfram Language function, https://reference.wolfram.com/language/ref/Pick.html.
CMS
Wolfram Language. 2004. "Pick." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Pick.html.
Wolfram Language. 2004. "Pick." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Pick.html.
APA
Wolfram Language. (2004). Pick. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Pick.html
Wolfram Language. (2004). Pick. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Pick.html
BibTeX
@misc{reference.wolfram_2024_pick, author="Wolfram Research", title="{Pick}", year="2004", howpublished="\url{https://reference.wolfram.com/language/ref/Pick.html}", note=[Accessed: 08-January-2025
]}
BibLaTeX
@online{reference.wolfram_2024_pick, organization={Wolfram Research}, title={Pick}, year={2004}, url={https://reference.wolfram.com/language/ref/Pick.html}, note=[Accessed: 08-January-2025
]}