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.
- If sel is a DataStructure object of type "BitVector", Pick[list,sel] retrieves the elements of list corresponding to the value 1 in sel. »
- Parallelize[Pick[list,sel]] computes Pick[list,sel] in parallel on all subkernels. »
Examples
open all close allBasic Examples (2)
Scope (5)
Pick out elements wherever True appears in the "selector" list:
Pick[{a, b, c, d}, {True, False, False, True}]Pick elements whose parts match a pattern:
Pick[{a, b, c, d}, {1, 2, 3, 4}, 2 | 4]Use a SparseArray to select arguments:
sel = SparseArray[{1 -> True, 100 -> True, _ -> False}, 100]Pick[Range[100], sel]Pick elements from a SparseArray:
data = SparseArray[{{1, 3} -> 2, {2, 2} -> 3, {3, 3} -> 5}]Pick[data, IdentityMatrix[3], 1]Create a data structure of type "BitVector" and length five:
ds = CreateDataStructure["BitVector", 5];Set its second and fourth bits to 1, cognizant of the fact that it is 0-indexed rather than 1-indexed:
ds["BitSet", 1];
ds["BitSet", 3]Extract those elements of a list using the data structure:
Pick[{a, b, c, d, e}, ds]Generalizations & Extensions (3)
The data does not have to be a list:
Pick[f[1, 2, 3, 4, 5, 6], {1, 0, 1, 0, 1, 1}, 1]The selector argument need not be a list:
Pick[{1, 2, 3, 4, 5, 6}, f[1, 0, 1, 0, 1, 1], 1]Convert strings to a list of characters to pick only certain characters:
Pick[Characters["ABC"], {True, False, True}]Applications (1)
Use Pick with a normal list of True and False:
selector = RandomChoice[{True, False}, 10 ^ 7];
data = Range[10 ^ 7];
AbsoluteTiming[pick = Pick[data, selector];]The same operation using the corresponding DataStructure is much faster:
ds = CreateDataStructure["BitVector", selector];
AbsoluteTiming[pick2 = Pick[data, ds];]pick === pick2Properties & Relations (3)
The comparison in Pick[list,sel,patt] is purely structural, with no regard to heads:
sel = {1, Cos[1], Sin[1]};
list = {a, b, f[b]};
Pick[list, sel, 1]f[b] is selected because the 3,1 part of sel matches the patt:
sel[[3, 1]]The corresponding part of list, if it exists, will be picked, along with its heads:
list[[3, 1]]Note that the 2,1 part of sel also matches patt:
sel[[2, 1]]However, there is no corresponding part of list to be picked:
list[[2, 1]]Compute Pick in parallel:
Parallelize[Pick[{a, b, c, d}, {1, 0, 1, 1}, 1]]If sel is a bit vector, Pick[list,sel] retrieves the elements of list corresponding to the value 1 in sel:
Pick[{a, b, c, d, e}, DataStructure["BitVector", {"Data" -> ByteArray["Cg=="], "Capacity" -> 5, "BitCount" -> 2}]]DataStructure["BitVector", {"Data" -> ByteArray["Cg=="], "Capacity" -> 5, "BitCount" -> 2}]["Boole"]//NormalPossible Issues (4)
The "selector" list has to have the same length and structure as the data:
Pick[{a, b, c, d}, {True, False}]Atomic expressions are allowed in Pick:
Pick[x, {1, 2, 3}, _List]This is because all parts—including the empty part—are tested for matching:
MatchQ[{1, 2, 3}[[]], _List]x[[]]If there is an atomic argument and it is not picked in its entirety, Sequence[] is returned:
Pick[x, {1, 2, 3}, _ ? NumericQ]This applies equally to the second argument:
Pick[{1, 2, 3}, False]Using Except[c] in the third argument can lead to unexpected results:
Pick[{a, b, c, d, e}, {1, 0, 1, 0, 0}, Except[1]]The whole expression is returned because the entire selector argument matches the pattern:
MatchQ[{1, 0, 1, 0, 0}, Except[1]]Use Except[c,p] to restrict the pattern to elements of the selector argument:
Pick[{a, b, c, d, e}, {1, 0, 1, 0, 0}, Except[1, _Integer]]Using nonatomic expressions in the selector argument can lead to unexpected results:
list = {1, x + y + z};
selector = {1, x + 2};
Pick[list, selector, _Integer]Applying the test beforehand so the list only contains True and False avoids the structure issue:
newSelector = Map[MatchQ[#, _Integer]&, selector]Pick[list, newSelector]Tech Notes
Related Guides
History
Introduced in 2004 (5.1) | Updated in 2025 (14.3)
Text
Wolfram Research (2004), Pick, Wolfram Language function, https://reference.wolfram.com/language/ref/Pick.html (updated 2025).
CMS
Wolfram Language. 2004. "Pick." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2025. 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
BibTeX
@misc{reference.wolfram_2026_pick, author="Wolfram Research", title="{Pick}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/Pick.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_pick, organization={Wolfram Research}, title={Pick}, year={2025}, url={https://reference.wolfram.com/language/ref/Pick.html}, note=[Accessed: 13-June-2026]}