ecl-logo Documentation

PickList

PickList[list, sel]filteredList

finds those elements of list for which the corresponding element of sel is True and returns a list of those elements.

PickList[list, sel, pattern]filteredList

finds those elements of list for which the corresponding element of sel matches pattern, and returns a list of those elements.

Details

  • PickList behaves similarly to the Mathematica function Pick, except for in the following cases, where Pick can behave in unusual ways:
  • If list = {a, b, f[b]} and sel = {1, Cos[1], Sin[1]}, that Pick[list, sel, 1] returns {a, f[b]} because it works on sequences regardless of their head. PickList works only on the list level so, PickList[list, sel, 1] will return {a}.
  • PickList matches only on lists and not sequences, and thus will not function at multiple depths or with arbitrary sequences.
  • PickList does not work with SparseArrays as Pick does.
  • PickList is substantially slower than Pick in the case of very large lists of inputs.
  • Input
    Output
    Messages
  • MismatchedListLengthExpressions `1` and `2` have incompatible shapes.

Examples

Basic Examples  (5)

PickList out only those elements whenever a 1 appears in the "selector" list:

PickList out only those elements where the "selector" list is True:

PickList out only those elements where the "selector" list matches the pattern:

PickList out only those elements where the "selector" list matches the pattern, where the pattern is more complex:

PickList out only those elements whose parts match the pattern:

Additional Examples  (10)

In cases where items in the list and sel have explicit heads, PickList looks only at the list level:

In cases where items in the list and sel have explicit heads, Pick looks at the sequence level:

Pick is substantially faster than Pick when working with very large lists:

PickList is substantially slower than Pick when working with very large lists:

Unlike PickList, Pick does accept sparse arrays as selectors:

Unlike PickList, Pick works at greater levels of depth in the expression:

Unlike PickList, Pick works on arbitrary sequences:

Unlike Pick, PickList does not accept sparse arrays as selectors:

Unlike Pick, PickList does works only on the first level of the list:

Unlike Pick, PickList only works on lists and not arbitrary sequences:

Messages  (1)

MismatchedListLength  (1)

The "selector" list must be the same length as the input list:

Last modified on Fri 26 Aug 2022 23:03:00