SubsetMap
更多信息
- 在 SubsetMap[f,list,{i1,…,in}] 中,函数 f 接受 list 中长度为 n 的子列表,并预期返回长度为 n 的另一个列表,其元素会取代原始子列表.
范例
打开所有单元 关闭所有单元基本范例 (5)
SubsetMap[Reverse, {x1, x2, x3, x4, x5, x6}, {2, 4}]SubsetMap[RotateLeft, {x1, x2, x3, x4, x5, x6}, {2, 4, 5}]SubsetMap[Accumulate, {x1, x2, x3, x4, x5, x6}, 2 ;; 5]SubsetMap[Reverse, Array[Subscript[x, ##]&, {3, 3}], {{1, 1}, {2, 2}, {3, 3}}]//MatrixFormSubsetMap[Accumulate, Array[Subscript[x, ##]&, {3, 3}], {All, 2}]//MatrixForm范围 (4)
SubsetMap[Reverse, Range[10], {2, 4, 6, 8, 10}]SubsetMap[Reverse, Range[10], {{2}, {4}, {6}, {8}, {10}}]SubsetMap[Reverse, Range[10], 2 ;; -1 ;; 2]SubsetMap[Reverse, {{a, b}, {c}}, {{1, 1}, {2, 1}}]SubsetMap[Reverse, {{a, b}, {c}}, {All, 1}]使用 SubsetMap 作为算符格式显示这些单词是“偶字母回文”:
Characters[{"rehabilitate", "semiparasite"}]SubsetMap[Reverse, {2, 4, 6, 8, 10, 12}] /@ %NestList[SubsetMap[RotateRight, Range[5, 10]], Hue /@ Subdivide[0, 0.8, 12], 12]//MatrixForm应用 (1)
randomSort[list_] := With[{n = Length[list]}, NestWhileList[SubsetMap[Sort, #, Sort@RandomInteger[{1, n}, 2]]&, list, Not @* OrderedQ]]randomSort[Reverse@Range[4]]ListLinePlot[Transpose[%]]Length[list = randomSort[Reverse@Range[20]]]ListLinePlot[Transpose[list], ScalingFunctions -> {"Log", None}]属性和关系 (4)
使用 SubsetMap 移动列表中元素子集的位置:
alphabet = Alphabet[]SubsetMap[RotateRight, alphabet, {1, 13, 25}]这也可以用 Cycles 符号和 Permute 紧凑表达:
% === Permute[alphabet, Cycles[{{1, 13, 25}}]]对于可列函数 f,SubsetMap[f,expr,pos] 等同于 MapAt[f,expr,pos]:
SubsetMap[Sqrt, Range[10], {{2}, {3}, {5}, {7}}]MapAt[Sqrt, Range[10], {{2}, {3}, {5}, {7}}]SubsetMap[f,expr,{}] 返回 expr:
SubsetMap[Accumulate, {a, b, c, d, e, f}, {}]SubsetMap[f,expr,All] 等同于 f[expr]:
SubsetMap[Accumulate, {a, b, c, d, e, f}, All]可能存在的问题 (2)
SubsetMap[Accumulate, {a, b, c}, {3, 2, 1}]在 SubsetMap[f,expr,{i,j,…}] 中,列表 {i,j,…} 表示位置列表,等价于 {{i},{j},…}:
expr = {x[1, a], x[2, b], x[3, c]};SubsetMap[Accumulate, expr, {1, 2}]SubsetMap[Accumulate, expr, {{1}, {2}}]其他使用位置规范的函数,例如 Extract,把整数列表诠释为单个位置:
Extract[expr, {1, 2}]Extract[expr, {{1}, {2}}]文本
Wolfram Research (2019),SubsetMap,Wolfram 语言函数,https://reference.wolfram.com/language/ref/SubsetMap.html.
CMS
Wolfram 语言. 2019. "SubsetMap." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/SubsetMap.html.
APA
Wolfram 语言. (2019). SubsetMap. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/SubsetMap.html 年
BibTeX
@misc{reference.wolfram_2026_subsetmap, author="Wolfram Research", title="{SubsetMap}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/SubsetMap.html}", note=[Accessed: 03-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_subsetmap, organization={Wolfram Research}, title={SubsetMap}, year={2019}, url={https://reference.wolfram.com/language/ref/SubsetMap.html}, note=[Accessed: 03-November-2026]}