SubsetMap

SubsetMap[f,{e1,e2,},{i,j,}]

yields an expression in which the elements ei, ej, in the list {e1,e2,} are replaced with the corresponding elements of the list obtained by evaluating f[{ei,ej,}].

SubsetMap[f,expr,{pos1,pos2,}]

replaces elements of expr at positions pos1, pos2, .

SubsetMap[f,{pos1,pos2,}]

represents an operator form of SubsetMap that can be applied to an expression.

Details

  • In SubsetMap[f,list,{i1,,in}], the function f takes a length-n sublist of list and is expected to return another list of length n, whose elements will replace those of the original sublist.

Examples

open all close all

Basic Examples  (5)

Reverse elements at positions 2 and 4:

In[1]:=
Click for copyable input
Out[1]=

Extract, rotate and reinsert elements at positions 2, 4 and 5:

In[1]:=
Click for copyable input
Out[1]=

Extract, accumulate and reinsert elements at positions 2 to 5:

In[1]:=
Click for copyable input
Out[1]=

Reverse the elements of the diagonal of a matrix:

In[1]:=
Click for copyable input
Out[1]//MatrixForm=

Accumulate the elements of the second column of a matrix:

In[1]:=
Click for copyable input
Out[1]//MatrixForm=

Scope  (4)

Applications  (1)

Properties & Relations  (4)

Possible Issues  (2)

Introduced in 2019
(12.0)