ReplacePart
Usage
• ReplacePart[expr, new, n] 得到一个表达式,且在该表达式中expr的第n个部分由new替换.
• ReplacePart[expr, new, i, j, ... ] 替换 i, j, ...  位置上的部分.
• ReplacePart[expr, new, pos, npos] 用new中npos位置上的部分替换expr中pos位置上的部分.
Notes
• ReplacePart 所使用的位置列表与函数Position所返回的具有相同形式. • ReplacePart[expr, Hold[new], pos, 1] 可以用来替换一个不对它进行计算的部分. • 如果 pos 和 npos 都指定多个部分, pos 中的每个部分用npos中相应的部分替换.
Further Examples
This puts x into the third part of the expression.
In[1]:=
|
Out[1]=
|
A powerful application of ReplacePart is in the partial evaluation of a held expression. Here's a function that takes an expression and a list of positions, and evaluates in place the parts at the specified positions.
In[2]:=
|
In this case, {1,2} specifies the second element of the held list, and {1,-1,1} the first part of the last element.
In[3]:=
|
Out[3]=
|
In[4]:=
|
|