ArrayPad
更多信息和选项
- 可以指定下列形式的填充:
-
c 常数 c {c1,c2,…} 循环重复常数 c1,… "Extrapolated" 元素的多项式外推法 "Fixed" 每边重复元素 "Periodic" 完全数组的循环重复 "Reflected" 边界上数组的映射 "ReflectedDifferences" 元素间差别的映射 "Reversed" 完全数组的逆 "ReversedDifferences" 元素间差别的逆 "ReversedNegation" 数组的否定逆 - 填充值 "Fixed" 指明在每个角增加的元素是原数组的各个角元素的复制.
- "Reversed" 表示数组中最外层元素应作为填充的最内层元素进行重复. "Reflected" 指定这些元素不需要重复.
- 填充值为 "Extrapolated" 时,多项式的次数通过选项 InterpolationOrder 指定.
- ArrayPad 可以填充任意深度的完全数组.
- ArrayPad 对 SparseArray 对象起作用.
- ArrayPad[array,-m] 从 array 的每边删除 m 个元素.
范例
打开所有单元 关闭所有单元基本范例 (6)
ArrayPad[{1, 2, 3}, 1]ArrayPad[{{1, 2}, {3, 4}}, 2] // MatrixFormArrayPad[{1, 2, 3}, {2, 4}]ArrayPad[{1, 2, 3}, 2, x]ArrayPad[{1, 2, 3}, 2, "Fixed"]ArrayPad[{{1, 2}, {3, 4}}, {{1}, {5}}] // MatrixForm范围 (12)
ArrayPad[{1, 2, 3}, {0, 2}]ArrayPad[Range[10], -2]ArrayPad[{{1, 2}, {3, 4}}, {{1}, {0}}] //MatrixFormArrayPad[{{1, 2}, {3, 4}}, {{0}, {1}}] //MatrixFormArrayPad[{{1, 2}, {3, 4}}, {{-1, 2}, {1, 3}}]//MatrixFormArrayPad[{{1, 2}, {3, 4}}, {{1}}]ArrayPad[{a, b, c}, 4, "Periodic"]ArrayPad[{a, b, c}, 4, "Reversed"]ArrayPad[{a, b, c}, 4, "ReversedNegation"]ArrayPad[{a, b, c}, 4, "Reflected"]ArrayPad[{a, b, c}, 3, "ReflectedDifferences"]Differences[%]ArrayPad[{a, b, c}, 4, "ReversedDifferences"]Differences[%]ArrayPad[{a, b, c}, 3, "Extrapolated"]Table[ArrayPad[{1, 4, 9}, 4, "Extrapolated", InterpolationOrder -> o], {o, 0, 2}] //MatrixFormArrayPad[N[Exp[Range[0, 5]]], 5, "Extrapolated", InterpolationOrder -> ∞]推广和延伸 (1)
ArrayPad 对 SparseArray 对象起作用:
ArrayPad[SparseArray[{i_, i_} -> i, {4, 4}], {{0}, {4}}, "ReversedNegation"]MatrixForm[%]选项 (3)
InterpolationOrder (3)
ArrayPad[{1, 5, 7, 8}, {0, 3}, "Extrapolated", InterpolationOrder -> 2]ArrayPad[{1, 5, 7, 8}, {0, 3}, "Extrapolated"]ArrayPad[{1, 5, 7, 8}, {0, 3}, "Extrapolated", InterpolationOrder -> ∞]属性和关系 (2)
PadLeft[list,n] 和 PadRight[list,n] 填充为长度 n 的一个列表:
PadLeft[{1, 2, 3}, 5]PadRight[{1, 2, 3}, 5]ArrayPad[list,n] 在每边填充 n 个其它元素:
ArrayPad[{1, 2, 3}, 5]对一维列表,ArrayPad[list,{-n,0}] 实际上是 Drop[list,n]:
{ArrayPad[{1, 2, 3, 4}, {-2, 0}], Drop[{1, 2, 3, 4}, 2]}ArrayPad[list,{0,-n}] 实际上是 Drop[list,-n]:
{ArrayPad[{1, 2, 3, 4}, {0, -2}], Drop[{1, 2, 3, 4}, -2]}可能存在的问题 (2)
ArrayPad[{{1, 2, 4}}, {1, 2}, "ReflectedDifferences"]ArrayPad[{{1, 2, 4}}, {{0, 0}, {1, 2}}, "ReflectedDifferences"]ArrayPad[{{}, {}}, 1, x]ArrayPad[{{}, {}}, 1, "Fixed"]巧妙范例 (1)
a = KroneckerProduct[Sqrt[Range[6]], Sqrt[Range[6]]];MatrixPlot[a]Table[MatrixPlot[ArrayPad[a, 4, p], Epilog -> {EdgeForm[{Thick, Red}], Transparent, Rectangle[{4, 4}, {10, 10}]}, FrameTicks -> None, PlotLabel -> p], {p, {"Fixed", "Extrapolated", "Periodic", "Reflected", "ReflectedDifferences", "Reversed", "ReversedDifferences", "ReversedNegation"}}]Table[MatrixPlot[ArrayPad[a, 12, p], Epilog -> {EdgeForm[{Thick, Red}], Transparent, Rectangle[{12, 12}, {18, 18}]}, FrameTicks -> None, PlotLabel -> p], {p, {"Fixed", "Extrapolated", "Periodic", "Reflected", "ReflectedDifferences", "Reversed", "ReversedDifferences", "ReversedNegation"}}]文本
Wolfram Research (2008),ArrayPad,Wolfram 语言函数,https://reference.wolfram.com/language/ref/ArrayPad.html.
CMS
Wolfram 语言. 2008. "ArrayPad." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/ArrayPad.html.
APA
Wolfram 语言. (2008). ArrayPad. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/ArrayPad.html 年
BibTeX
@misc{reference.wolfram_2026_arraypad, author="Wolfram Research", title="{ArrayPad}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/ArrayPad.html}", note=[Accessed: 10-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_arraypad, organization={Wolfram Research}, title={ArrayPad}, year={2008}, url={https://reference.wolfram.com/language/ref/ArrayPad.html}, note=[Accessed: 10-August-2026]}