select
selection from an expression
remove
removal from an expression
selectremove
selection or removal from an expression
Calling Sequence
Parameters
Description
Arguments and Options
Objects Supporting select, remove, and selectremove
Thread Safety
Examples
Compatibility
select(fcn, expr, arg2, ..., argN)
select[n](fcn, arg1, ..., argn-1, expr, argn+1, ..., argN)
select[flatten](fcn, expr, arg2, ..., argN)
select[inplace](fcn, expr, arg2, ..., argN)
select[indices](fcn, expr, arg1, ..., argN)
select[fold=(rfcn,zero)](fcn, expr, arg1, ..., argN)
select[reduce=rfcn](fcn, expr, arg1, ..., argN)
select[scan=sfcn](fcn, expr, arg1, ..., argN)
remove(fcn, expr, arg2, ..., argN)
remove[n](fcn, arg1, ..., argn-1, expr, argn+1, ..., argN)
remove[flatten](fcn, expr, arg2, ..., argN)
remove[inplace](fcn, expr, arg2, ..., argN)
remove[fold=(rfcn,zero)](fcn, expr, arg1, ..., argN)
remove[reduce=rfcn](fcn, expr, arg1, ..., argN)
remove[scan=sfcn](fcn, expr, arg1, ..., argN)
selectremove(fcn, expr, arg2, ..., argN)
selectremove[n](fcn, arg1, ..., argn-1, expr, argn+1, ..., argN)
selectremove[flatten](fcn, expr, arg2, ..., argN)
selectremove[inplace](fcn, expr, arg2, ..., argN)
selectremove[fold=(rfcn,zero)](fcn, expr, arg1, ..., argN)
selectremove[reduce=rfcn](fcn, expr, arg1, ..., argN)
selectremove[scan=rfcn](fcn, expr, arg1, ..., argN)
fcn
-
Boolean-valued procedure
expr
any expression
arg1, ..., argN
(optional) further arguments to fcn
n
positive integer
rfcn
a function to apply to the result of select or remove to reduce it to a single value
zero
the starting value when computing the reduction
The select function selects the operands of the expression expr which satisfy the Boolean-valued procedure fcn, and creates a new object of the same type as expr. Those operands for which fcn does not return true are discarded in the newly created object.
The remove function does the opposite of select. It removes the operands of expr for which fcn returns true and creates a new object containing the remaining operands.
The selectremove function behaves in the same manner as select(..) and remove(..), except that the result is computed efficiently, in a single pass over expression expr. The return value is a sequence of two objects of the same type as expr.
When expr is an ordered expression, such as a list or unevaluated function call, the operands of the output retain their relative order. If the expression expr is an expression of type ^ and the result consists only of an exponent with a null base, then the output is undefined.
A typical application of select and remove is to split the factors of a product, expr, into those which depend on a variable x and those which do not (that is, constants). This can be accomplished by using v := select( has, expr, x ) followed by c := remove( has, expr, x ). It is more efficient, however, to use v, c := selectremove( has, expr, x ). Do not try to compute c := expr / v. Because of the way Maple simplifies expressions, factors do not cancel out in general. See the last example below.
Some options can be specified in square brackets as an index to the select, remove, or selectremove commands. These options can be used by themselves or in combination with other options. Any option described for select below can also be used with remove or selectremove unless otherwise noted.
select(fcn, expr, arg2, ..., argN) executes fcn(elem, arg2, ..., argN) for each operand or element of expr. The value returned by fcn must be true, false, or FAIL.
Instead of a Boolean-valued procedure, fcn can be specified as a list, Array, or Vector of Boolean- or integer-valued expressions. As each operand of expr is encountered, the corresponding entry of fcn is used to decide whether to keep (or remove) it:
A value of true or 1 indicates the element from expr is to be kept (for select) or dropped (for remove).
A value of false or 0 indicates the element from expr is to be dropped (for select) or kept (for remove).
If fcn has too few entries to specify all the operands of expr, the missing entries are assumed to be false. If it has too many entries, the extra entries are ignored.
The form select[n](fcn, arg1, ..., argn-1, expr, argn+1, ..., argN), where n is a positive integer, passes the element of expr as the n-th argument of fcn. Thus select[1] is equivalent to select.
When expr is an Array, Vector, Matrix, or table, the select[flatten] form can be used. This causes the result to be flattened to a one-dimensional structure with all discarded elements removed (as opposed to having the discarded elements replaced with NULL).
When expr is an Array, Matrix, Vector, table, or an object implementing a mutable container, the select[inplace] form can be used. This causes the selection to be applied to the container in-place (for example, in the case of select[inplace], the non-selected entries in the container are removed from expr itself). When selectremove[inplace] is called, the first result is computed in-place, and the removed elements are returned in a new container that is returned as the second result.
The indices option applies only when selecting from an rtable, list, set, or function, and causes fcn to be passed the index of each entry instead of the value. Thus, the decision to keep or discard an entry can be made based on its index, rather than its value. Note that if an rtable has more than one dimension, multiple arguments are passed for the index, one per dimension.
The fold option specifies a function, rfcn, and an initial value, zero, used to reduce the result of select or remove to a single value instead of returning a modified copy of expr. The value is initialized to that specified by zero. Then, for each retained element of expr, rfcn is applied to the value and that element, and the value is updated.
The reduce option is similar to fold, except that the value is initialized to the first retained element of the result. Application of rfcn then begins with the value and the next element.
Both fold and reduce compute the single result without actually creating the modified copy of expr. Instead, the result value is updated as each individual is computed. This prevents the allocation of a potentially large amount of memory for an intermediate result that would be discarded.
An additonal option, evalhf, can be used with fold or reduce, in which case each call to rfcn is evaluated using evalhf, and the final result returned is a hardware float.
Note that fold and reduce are equivalent when the result of selecting or removing elements of expr is not empty, and the specified zero is the natural zero (or identity) of the reduction function. For example, the natural zero of addition is 0, and of multiplication is 1.
If the result of selecting or removing elements is empty, reduce will return undefined, whereas fold will return zero.
The fold or reduce options cannot be used in conjunction with the flatten or inplace options.
The scan option is related to reduce, except that instead reducing the result otherwise produced by select to a single value, each prefix of that result is reduced to a single result. It is equivalent to mapping map[reduce] over each prefix of the result produced by the call to select, without having to compute the intermediate prefix separately.
The fold, reduce, and scan options are mutually exclusive.
The following objects support the select, remove, and selectremove commands with a separate implementation. See the help pages linked below for more details.
"DataFrame" objects
"DataSeries" objects
Using the flatten and inplace options together is permitted, but is not thread safe.
The select, remove and selectremove commands are thread-safe as of Maple 15.
For more information on thread safety, see index/threadsafe.
integers≔seq⁡10..20
integers≔10,11,12,13,14,15,16,17,18,19,20
select⁡isprime,integers
11,13,17,19
remove⁡isprime,integers
10,12,14,15,16,18,20
selectremove⁡isprime,integers
11,13,17,19,10,12,14,15,16,18,20
f≔2⁢exp⁡a⁢x⁢sin⁡x⁢ln⁡y
f≔2⁢ⅇa⁢x⁢sin⁡x⁢ln⁡y
select⁡has,f,x
ⅇa⁢x⁢sin⁡x
remove⁡has,f,x
2⁢ln⁡y
selectremove⁡has,f,x
ⅇa⁢x⁢sin⁡x,2⁢ln⁡y
f≔yx
undefined,y
f≔indets⁡f
f≔x,y,yx
select⁡type,f,name
x,y
remove⁡type,f,name
yx
selectremove⁡type,f,name
x,y,yx
f≔2⁢ln⁡x⁢y+1
c≔remove⁡has,f,x
c≔2⁢y+2
fc
2⁢ln⁡x⁢y+12⁢y+2
ln⁡x
remove⁡x↦2<x,1,2,3
12
removeflatten⁡x↦2<x,1,2,3
The following example selects any entries of a matrix matching a certain criteria, showing NULL for any entries that do not match. To see an example of removing any rows or columns that do not match a given criteria, see the Working with Subsections of Data - Extracting Data section in the LA_syntax_shortcuts page.
select⁡x↦2<x,1|2,3|4
34
selectflatten⁡x↦2<x,1|2,3|4
The inplace option lets a selection decision to be made based on an entry's index.
unassign⁡a,b,c,d
selectindices⁡type,a,b,c,d,odd
a,c
selectindices⁡row,col↦row=col,a|b,c|d
ad
A reduction or fold function is applied to the selected values.
selectreduce=`+`⁡isprime,integers
60
removefold=`*`,1⁡isprime,integers
145152000
A selection function need not take the entry value as the first argument.
between≔lo,x,hi↦lo≤x≤hi:
select2⁡between,12,integers,17
12,13,14,15,16,17
selectremove2⁡between,5,integers,15
10,11,12,13,14,15,16,17,18,19,20
selectremove2,reduce=`+`⁡between,5,integers,15
75,90
Using a list of Boolean values instead of a function to select operands is useful if the same selection is to be applied to multiple expressions.
nums≔1,2,3,4,5,6,7,8,9,10
names≔map2⁡nprintf,a%03d,nums
names≔a001,a002,a003,a004,a005,a006,a007,a008,a009,a010
selector≔map⁡type,nums,odd
selector≔true,false,true,false,true,false,true,false,true,false
select⁡selector,nums
1,3,5,7,9
select⁡selector,names
a001,a003,a005,a007,a009
The scan option is equivalent to mapping map[reduce] over each prefix of the data produced by a simple call to select:
L≔select⁡type,1,2,3,4,5,6,7,8,9,10,odd
L≔1,3,5,7,9
prefixes≔seq⁡L1..n,n=1..numelems⁡L
prefixes≔1,1,3,1,3,5,1,3,5,7,1,3,5,7,9
map⁡x↦mapreduce=`+`⁡y↦y,x,prefixes
1,4,9,16,25
selectscan=`+`⁡type,1,2,3,4,5,6,7,8,9,10,odd
The flatten option was introduced in Maple 17.
For more information on Maple 17 changes, see Updates in Maple 17.
The inplace option was introduced in Maple 2018.
For more information on Maple 2018 changes, see Updates in Maple 2018.
The select, remove and selectremove commands were updated in Maple 2021.
The select[n], select[indices], select[fold], select[reduce], select[scan], remove[n], remove[indices], remove[fold], remove[reduce], remove[scan], selectremove[n], selectremove[fold], selectremove[reduce], selectremove[scan] and options were introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
See Also
member
membertype
selectfun
Download Help Document