QuantityArray[mags,unit]
表示带有大小 mags 和常用 unit 的数量数组.
QuantityArray[mags,{unit1,unit2,…}]
表示带有单位 {unit1,unit2,…} 的数量列表数组.
QuantityArray[quants]
把 Quantity 对象的数组转换为单个 QuantityArray 对象的数组.
QuantityArray
QuantityArray[mags,unit]
表示带有大小 mags 和常用 unit 的数量数组.
QuantityArray[mags,{unit1,unit2,…}]
表示带有单位 {unit1,unit2,…} 的数量列表数组.
QuantityArray[quants]
把 Quantity 对象的数组转换为单个 QuantityArray 对象的数组.
更多信息
- QuantityArray[…] 被转换为形为 QuantityArray[StructuredData[dims,{mags,…}]] 结构化数组表达式.
- 在 QuantityArray[mags,unit] 中,大小 mags 的数组可以是任意深度和维度的完全数组.
- 在 QuantityArray[mags,{unit1,unit2,…}] 中,uniti 列表的长度必须与 mags 最深的维度一致.
- 在 QuantityArray[mags,…] 中,mags 可以是一个 SparseArray 对象.
- Normal 将 QuantityArray 对象转换为 Quantity 对象的数组. 要避免其他结构的规范化,例如 SparseArray 或无量纲 Quantity 对象,请使用 Normal[qa,QuantityArray]. »
范例
打开所有单元 关闭所有单元基本范例 (3)
qa = QuantityArray[{2.3, 1.5, 9.0}, "Meters"]QuantityMagnitude[qa]QuantityUnit[qa]Normal[qa]qa = QuantityArray[{{1.4, 2.3}, {2.8, 2.7}, {4.2, 3.5}}, {"Seconds", "Meters"}]QuantityMagnitude[qa]QuantityUnit[qa]UnitConvert[qa, {"Minutes", "Feet"}]Normal[%]把数量的规范化数组转换为 QuantityArray 表示:
{{Quantity[1, "Seconds"], Quantity[3, "Newtons"]}, {Quantity[2, "Seconds"], Quantity[8, "Newtons"]}}QuantityArray[%]范围 (6)
QuantityArray[RandomReal[1, {10, 3}], "Meters"]QuantityArray[{Quantity[1, "Meters"], Quantity[2, "Meters"], Quantity[3, "Meters"]}]QuantityArray[RandomReal[1, {10, 8, 3}], {"Meters", "Seconds", "Kilograms"}]QuantityArray[{{Quantity[1, "Meters"], Quantity[2, "Seconds"], Quantity[3, "Kilograms"]}, {Quantity[4, "Meters"], Quantity[5, "Seconds"], Quantity[6, "Kilograms"]}}]QuantityArray[RandomReal[1, {10, 8, 2, 2}], {{"Meters", "Seconds"}, {"Kilograms", "Newtons"}}]QuantityArray[{{{Quantity[1, "Meters"], Quantity[2, "Seconds"]}, {Quantity[3, "Kilograms"], Quantity[4, "Newtons"]}}, {{Quantity[5, "Meters"], Quantity[6, "Seconds"]}, {Quantity[7, "Kilograms"], Quantity[8, "Newtons"]}}}]构建一个带有 IndependentUnit 规范的数量数组:
QuantityArray[Range[10], IndependentUnit["myUnit"]]把 Quantity 对象的数组转换为一个 QuantityArray 表达式:
qs = {{Quantity[1., "Kilograms"], Quantity[2., "Newtons"]}, {Quantity[5., "Kilograms"], Quantity[10., "Newtons"]}, {Quantity[3., "Kilograms"], Quantity[6., "Newtons"]}}QuantityArray[qs]QuantityArray 对象包含给出数组信息的属性:
qa = QuantityArray[RandomReal[1, {10, 2}], {"Seconds", "Meters"}]qa["Properties"]qa["Summary"]"StructuredAlgorithms" 属性给出具有使用表示结构的算法的函数列表:
qa["StructuredAlgorithms"]qa["Magnitudes"]qa["UnitBlock"]属性和关系 (8)
QuantityArray 对象被解释为 Quantity 对象的一个数组:
qa = QuantityArray[RandomReal[1, {20, 2}], {"Meters", "Seconds"}]ArrayQ[qa]MatrixQ[qa]VectorQ[qa]它是 Quantity 对象的数组,不是数字的数组:
MatrixQ[qa, QuantityQ]MatrixQ[qa, NumericQ]QuantityArray 的表示是使用高效的内存:
qa = QuantityArray[RandomReal[1, {100, 100, 2}], {"Meters", "Seconds"}]nqa = Normal[qa, QuantityArray];ByteCount[qa] / ByteCount[nqa]//NQuantityMagnitude[qa];//AbsoluteTimingQuantityUnit[qa];//AbsoluteTimingQuantityMagnitude[nqa];//AbsoluteTimingQuantityUnit[nqa];//AbsoluteTiming单个数量自动转换为 Quantity :
QuantityArray[7, "Meters"]%//InputFormQuantityArray[{7}, "Meters"]%//NormalQuantityArray[{7}, {"Meters"}]%//Normal在转换中,QuantityArray 不会尝试改变单位:
QuantityArray[{Quantity[1, "Meters"], Quantity[2, "Feet"]}]UnitConvert 会统一单位:
UnitConvert[%, "Meters"]Normal[%]在多个操作中,QuantityArray 结构被保留. 取两个数组:
qa = QuantityArray[{{1, 20}, {3, 40}, {5, 60}, {7, 50}}, {"Meters", "Seconds"}]qb = QuantityArray[{{10, 2}, {20, 2}, {30, 2}, {40, 2}}, {"Feet", "Seconds"}]带有兼容单位的 QuantityArray 对象的相加,自动转换其中一部分:
qa + qb带有兼容维度的 QuantityArray 对象的乘积:
qa qbQuantityArray 对象的张量乘积:
TensorProduct[qa, qb]Transpose[qa]%//InputFormFlatten[qa]%//InputFormPartition[qa, 2]%//InputFormFlatten[%%, 1]% == qa提取一个带有兼容但不同单位的 QuantityArray 对象:
qa = QuantityArray[{{1, 2}, {3, 4}, {5, 6}}, {"Meters", "Feet"}]CommonUnits 会把它转换为单个单位数组:
CommonUnits[qa]Normal[%]使用 UnitConvert 选择单位:
UnitConvert[qa, "Meters"]Normal[%]无穷精度的 QuantityArray 对象:
qa = QuantityArray[{{1, 2}, {3, 4}}, {"Meters", "Seconds"}]Precision[qa]nqa = N[qa, 20]Precision[nqa]InputForm[nqa]Precision[2. qa]QuantityArray 会自动尝试去解释为准的单位字符串:
QuantityArray[RandomReal[1, 10], "foot"]QuantityArray[{{1, 20}, {3, 40}, {5, 60}, {7, 50}}, {"fps", "Meterss"}]可能存在的问题 (1)
QuantityArray 对象的正规化也会对纯数字量进行正规化,例如百分比:
qa = QuantityArray[{10, 30, 79}, "Percent"]Normal[qa]指定仅应标准化 QuantityArray 结构:
Normal[qa, QuantityArray]相关的工作流程
- 含有单位的计算
文本
Wolfram Research (2015),QuantityArray,Wolfram 语言函数,https://reference.wolfram.com/language/ref/QuantityArray.html (更新于 2020 年).
CMS
Wolfram 语言. 2015. "QuantityArray." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2020. https://reference.wolfram.com/language/ref/QuantityArray.html.
APA
Wolfram 语言. (2015). QuantityArray. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/QuantityArray.html 年
BibTeX
@misc{reference.wolfram_2026_quantityarray, author="Wolfram Research", title="{QuantityArray}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/QuantityArray.html}", note=[Accessed: 03-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_quantityarray, organization={Wolfram Research}, title={QuantityArray}, year={2020}, url={https://reference.wolfram.com/language/ref/QuantityArray.html}, note=[Accessed: 03-November-2026]}