ArrayReshape[list,dims]
将 list 中的元素排列成一个维数为 dims 的矩形数组.
ArrayReshape[list,dims,padding]
如果 list 不含有足够元素,则使用指定的填充.
ArrayReshape
ArrayReshape[list,dims]
将 list 中的元素排列成一个维数为 dims 的矩形数组.
ArrayReshape[list,dims,padding]
如果 list 不含有足够元素,则使用指定的填充.
更多信息
- ArrayReshape 总是给出一个指定维数的矩形数组,在必要时忽略最后的元素,或添加新的元素.
- 在得到的数组中,元素的排列方式使得在长度范围内,Flatten[ArrayReshape[list,dims]] 与 Flatten[list] 的结果相同.
- 在 ArrayReshape[list,dims,padding] 中,可以使用任何可被 ArrayPad 支持的填充方式. 缺省的填充值为 0.
- ArrayReshape 适用于 SparseArray 对象.
范例
打开所有单元 关闭所有单元基本范例 (4)
ArrayReshape[{a, b, c, d, e, f}, {2, 3}]ArrayReshape[Range[24], {2, 3, 4}]ArrayReshape[{1, 2, 3, 4, 5, 6, 7}, {5, 3}, x]ArrayReshape[{10, 20, 30, 40, 50, 60, 70}, {5, 3}, "Extrapolated"]范围 (1)
推广和延伸 (1)
ArrayReshape 可用于 SparseArray 对象:
ArrayReshape[SparseArray[{1 -> 1, 4 -> 5}, 10], {2, 6}, x]MatrixForm[%]应用 (2)
属性和关系 (2)
基于 Partition 的函数等价于无填充的 ArrayReshape:
pareshape[list_, dims_] := Fold[Partition, Flatten[list], dims[[-1 ;; 2 ;; -1]]]pareshape[Range[24], {2, 3, 4}]% === ArrayReshape[Range[24], {2, 3, 4}]矩阵维数的逆反得到的元素次序与 Transpose 所得的次序不同:
m = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};ArrayReshape[m, Reverse[Dimensions[m]]]Transpose[m]文本
Wolfram Research (2012),ArrayReshape,Wolfram 语言函数,https://reference.wolfram.com/language/ref/ArrayReshape.html.
CMS
Wolfram 语言. 2012. "ArrayReshape." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/ArrayReshape.html.
APA
Wolfram 语言. (2012). ArrayReshape. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/ArrayReshape.html 年
BibTeX
@misc{reference.wolfram_2026_arrayreshape, author="Wolfram Research", title="{ArrayReshape}", year="2012", howpublished="\url{https://reference.wolfram.com/language/ref/ArrayReshape.html}", note=[Accessed: 04-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_arrayreshape, organization={Wolfram Research}, title={ArrayReshape}, year={2012}, url={https://reference.wolfram.com/language/ref/ArrayReshape.html}, note=[Accessed: 04-September-2026]}