GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • WOLFRAM
  • Products
  • AI AccessUse with Mathematica and Wolfram|One
  • Finance Platform
  • Wolfram|Alpha Notebook Edition
  • Application Server
  • Enterprise Private Cloud
  • Wolfram Engine
  • Wolfram Player
  • Wolfram Cloud App
  • Wolfram Player App
  • Wolfram|Alpha Website
  • Wolfram|Alpha APIs
  • Wolfram AI Ecosystem

This view

  • Original page
  • New address

GeezerVison is showing reference.wolfram.com — QuantityArray—Wolfram Documentation

QuantityArray[mags,unit]

represents an array of quantities with magnitudes mags and common unit.

QuantityArray[mags,{unit1,unit2,…}]

represents an array of lists of quantities with units {unit1,unit2,…}.

QuantityArray[quants]

converts an array of Quantity objects into a single QuantityArray object.

Details
Details and Options Details and Options
Examples  
Basic Examples  
Scope  
Properties & Relations  
Possible Issues  
See Also
Related Guides
Related Workflows
History
Cite this Page

QuantityArray

QuantityArray[mags,unit]

represents an array of quantities with magnitudes mags and common unit.

QuantityArray[mags,{unit1,unit2,…}]

represents an array of lists of quantities with units {unit1,unit2,…}.

QuantityArray[quants]

converts an array of Quantity objects into a single QuantityArray object.

Details

  • QuantityArray[…] is converted to a structured array expression of the form QuantityArray[StructuredData[dims,{mags,…}]].
  • In QuantityArray[mags,unit], the array of magnitudes mags can be a full array of any depth and dimensions.
  • In QuantityArray[mags,{unit1,unit2,…}], the length of the list of uniti must coincide with the deepest dimension of mags.
  • In QuantityArray[mags,…], mags can be a SparseArray object.
  • Normal converts QuantityArray objects to arrays of Quantity objects. To avoid normalization of other structures, like SparseArray or dimensionless Quantity objects, use Normal[qa,QuantityArray]. »

Examples

open all close all

Basic Examples  (3)

A list of lengths, all given in meters:

Wolfram Language code: qa = QuantityArray[{2.3, 1.5, 9.0}, "Meters"]

Extract its magnitudes and units separately:

Wolfram Language code: QuantityMagnitude[qa]
Wolfram Language code: QuantityUnit[qa]

Normalize the quantity array:

Wolfram Language code: Normal[qa]

A list of pairs {time,length}:

Wolfram Language code: qa = QuantityArray[{{1.4, 2.3}, {2.8, 2.7}, {4.2, 3.5}}, {"Seconds", "Meters"}]

Normalize it:

Wolfram Language code: Normal[qa]

Convert units:

Wolfram Language code: UnitConvert[qa, {"Minutes", "Feet"}]
Wolfram Language code: Normal[%]

Convert a normal array of quantities into a QuantityArray representation:

Wolfram Language code: {{Quantity[1, "Seconds"], Quantity[3, "Newtons"]}, {Quantity[2, "Seconds"], Quantity[8, "Newtons"]}}
Wolfram Language code: QuantityArray[%]

Scope  (6)

Construct an array of quantities with the same unit:

Wolfram Language code: QuantityArray[RandomReal[1, {10, 3}], "Meters"]

Convert a normal array of quantities with the same unit:

Wolfram Language code: QuantityArray[{Quantity[1, "Meters"], Quantity[2, "Meters"], Quantity[3, "Meters"]}]

Construct an array of tuples of quantities with different units:

Wolfram Language code: QuantityArray[RandomReal[1, {10, 8, 3}], {"Meters", "Seconds", "Kilograms"}]

Convert a normal matrix of quantities with the same units in each column:

Wolfram Language code: QuantityArray[{{Quantity[1, "Meters"], Quantity[2, "Seconds"], Quantity[3, "Kilograms"]}, {Quantity[4, "Meters"], Quantity[5, "Seconds"], Quantity[6, "Kilograms"]}}]

Construct an array of matrices of quantities with different units:

Wolfram Language code: QuantityArray[RandomReal[1, {10, 8, 2, 2}], {{"Meters", "Seconds"}, {"Kilograms", "Newtons"}}]

Convert a normal matrix of quantities with the same units in each subarray:

Wolfram Language code: 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"]}}}]

Construct an array of quantities with IndependentUnit specifications:

Wolfram Language code: QuantityArray[Range[10], IndependentUnit["myUnit"]]

Convert an array of Quantity objects into a QuantityArray expression:

Wolfram Language code: qs = {{Quantity[1., "Kilograms"], Quantity[2., "Newtons"]}, {Quantity[5., "Kilograms"], Quantity[10., "Newtons"]}, {Quantity[3., "Kilograms"], Quantity[6., "Newtons"]}}
Wolfram Language code: QuantityArray[qs]

QuantityArray objects include properties that give information about the array:

Wolfram Language code: qa = QuantityArray[RandomReal[1, {10, 2}], {"Seconds", "Meters"}]
Wolfram Language code: qa["Properties"]

The "Summary" property gives a brief summary of information about the array:

Wolfram Language code: qa["Summary"]

The "StructuredAlgorithms" property gives a list of functions that have algorithms that use the structure of the representation:

Wolfram Language code: qa["StructuredAlgorithms"]

The array of magnitudes and the elementary block of units can be extracted using properties:

Wolfram Language code: qa["Magnitudes"]
Wolfram Language code: qa["UnitBlock"]

Properties & Relations  (8)

A QuantityArray object is interpreted as an array of Quantity objects:

Wolfram Language code: qa = QuantityArray[RandomReal[1, {20, 2}], {"Meters", "Seconds"}]

It is an array:

Wolfram Language code: ArrayQ[qa]

It is a list of pairs; hence, a matrix, not a vector:

Wolfram Language code: MatrixQ[qa]
Wolfram Language code: VectorQ[qa]

It is an array of Quantity objects, not an array of numbers:

Wolfram Language code: MatrixQ[qa, QuantityQ]
Wolfram Language code: MatrixQ[qa, NumericQ]

The QuantityArray representation is memory efficient:

Wolfram Language code: qa = QuantityArray[RandomReal[1, {100, 100, 2}], {"Meters", "Seconds"}]
Wolfram Language code: nqa = Normal[qa, QuantityArray];

It uses only 6% of the memory of the corresponding normal representation:

Wolfram Language code: ByteCount[qa] / ByteCount[nqa]//N

It also allows faster extraction of magnitudes and units:

Wolfram Language code: QuantityMagnitude[qa];//AbsoluteTiming
Wolfram Language code: QuantityUnit[qa];//AbsoluteTiming

Compare to the slower extraction from the normal array of quantities:

Wolfram Language code: QuantityMagnitude[nqa];//AbsoluteTiming
Wolfram Language code: QuantityUnit[nqa];//AbsoluteTiming

A single quantity is automatically converted into a Quantity object:

Wolfram Language code: QuantityArray[7, "Meters"]
Wolfram Language code: %//InputForm

This is a list with one quantity:

Wolfram Language code: QuantityArray[{7}, "Meters"]
Wolfram Language code: %//Normal

It can also be given as:

Wolfram Language code: QuantityArray[{7}, {"Meters"}]
Wolfram Language code: %//Normal

During conversion, QuantityArray does not try to change units:

Wolfram Language code: QuantityArray[{Quantity[1, "Meters"], Quantity[2, "Feet"]}]

UnitConvert will unify the units:

Wolfram Language code: UnitConvert[%, "Meters"]
Wolfram Language code: Normal[%]

The QuantityArray structure is preserved in multiple operations. Take two arrays:

Wolfram Language code: qa = QuantityArray[{{1, 20}, {3, 40}, {5, 60}, {7, 50}}, {"Meters", "Seconds"}]
Wolfram Language code: qb = QuantityArray[{{10, 2}, {20, 2}, {30, 2}, {40, 2}}, {"Feet", "Seconds"}]

Addition of QuantityArray objects of compatible units, automatically converting some of them:

Wolfram Language code: qa + qb

Multiplication of QuantityArray objects of compatible dimensions:

Wolfram Language code: qa qb

Tensor product of QuantityArray objects:

Wolfram Language code: TensorProduct[qa, qb]

Transposition is special because it stores the permutation:

Wolfram Language code: Transpose[qa]
Wolfram Language code: %//InputForm

Flattening is also special in that sense:

Wolfram Language code: Flatten[qa]
Wolfram Language code: %//InputForm

Partition the array:

Wolfram Language code: Partition[qa, 2]
Wolfram Language code: %//InputForm

Flatten it again:

Wolfram Language code: Flatten[%%, 1]

The result is an equivalent representation of the original quantity array:

Wolfram Language code: % == qa

Take a QuantityArray object with compatible but different units:

Wolfram Language code: qa = QuantityArray[{{1, 2}, {3, 4}, {5, 6}}, {"Meters", "Feet"}]

CommonUnits will convert it into a single unit array:

Wolfram Language code: CommonUnits[qa]
Wolfram Language code: Normal[%]

To select the unit, use UnitConvert:

Wolfram Language code: UnitConvert[qa, "Meters"]
Wolfram Language code: Normal[%]

A QuantityArray object of infinite precision:

Wolfram Language code: qa = QuantityArray[{{1, 2}, {3, 4}}, {"Meters", "Seconds"}]
Wolfram Language code: Precision[qa]

Numericize to precision 20:

Wolfram Language code: nqa = N[qa, 20]
Wolfram Language code: Precision[nqa]
Wolfram Language code: InputForm[nqa]

The arithmetic operations take precision into account:

Wolfram Language code: Precision[2. qa]

QuantityArray will automatically attempt to interpret an unknown unit string:

Wolfram Language code: QuantityArray[RandomReal[1, 10], "foot"]
Wolfram Language code: QuantityArray[{{1, 20}, {3, 40}, {5, 60}, {7, 50}}, {"fps", "Meterss"}]

Possible Issues  (1)

Normalization of QuantityArray objects also normalizes purely numerical quantities such as percents:

Wolfram Language code: qa = QuantityArray[{10, 30, 79}, "Percent"]
Wolfram Language code: Normal[qa]

Specify that only the QuantityArray structure should be normalized:

Wolfram Language code: Normal[qa, QuantityArray]

See Also

Quantity  Normal  MapThread  QuantityMagnitude  QuantityUnit  UnitConvert  QuantityDistribution

Related Guides

    ▪
  • Structured Arrays
  • ▪
  • Units & Quantities

Related Workflows

    Related Workflows
    ▪
  • Calculate with Units

History

Introduced in 2015 (10.1) | Updated in 2020 (12.1)

Wolfram Research (2015), QuantityArray, Wolfram Language function, https://reference.wolfram.com/language/ref/QuantityArray.html (updated 2020).

Text

Wolfram Research (2015), QuantityArray, Wolfram Language function, https://reference.wolfram.com/language/ref/QuantityArray.html (updated 2020).

CMS

Wolfram Language. 2015. "QuantityArray." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/QuantityArray.html.

APA

Wolfram Language. (2015). QuantityArray. Wolfram Language & System Documentation Center. Retrieved from 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: 12-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: 12-November-2026]}

Top
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.