({{, (RefLink[QuantityArray, paclet:ref/QuantityArray])[mags,unit] 
represents an array of quantities with magnitudes mags and common unit.}, {, (RefLink[QuantityArray, paclet:ref/QuantityArray])[mags,{(Subscript[unit, 1]),(Subscript[unit, 2]),…}]
represents an array of lists of quantities with units {(Subscript[unit, 1]),(Subscript[unit, 2]),…}.}, {, (RefLink[QuantityArray, paclet:ref/QuantityArray])[quants]
converts an array of (RefLink[Quantity, paclet:ref/Quantity]) objects into a single (RefLink[QuantityArray, paclet:ref/QuantityArray]) object.}})

OpenersNotesSection(Spacer1)Details

In (RefLink[QuantityArray, paclet:ref/QuantityArray])[mags,unit], the array of magnitudes mags can be a full array of any depth and dimensions.

In (RefLink[QuantityArray, paclet:ref/QuantityArray])[mags,{(Subscript[unit, 1]),(Subscript[unit, 2]),…}], the length of the list of (Subscript[unit, i]) must coincide with the deepest dimension of mags.

In (RefLink[QuantityArray, paclet:ref/QuantityArray])[mags,…], mags can be a (RefLink[SparseArray, paclet:ref/SparseArray]) object.

(RefLink[QuantityArray, paclet:ref/QuantityArray])[…] returns (RefLink[StructuredArray, paclet:ref/StructuredArray]) expressions of structure type (RefLink[QuantityArray, paclet:ref/QuantityArray]).

(RefLink[Normal, paclet:ref/Normal]) converts (RefLink[QuantityArray, paclet:ref/QuantityArray]) objects to arrays of (RefLink[Quantity, paclet:ref/Quantity]) objects.

OpenersPrimaryExamplesSection(Spacer1)Examples  (18)

OpenersExampleSection0(Spacer1)Basic Examples  (3)

A list of lengths, all given in meters:

qa=QuantityArray[{2.3,1.5,9.0},"Meters"]

Extract its magnitudes and units separately:

QuantityMagnitude[qa]

QuantityUnit[qa]

Normalize the quantity array:

Normal[qa]

%//InputForm

A list of pairs {time,length}:

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

Extract its magnitudes and units separately:

QuantityMagnitude[qa]

QuantityUnit[qa]

Convert units:

UnitConvert[qa,{"Minutes","Feet"}]

Normal[%]

Convert a normal array of quantities into a (RefLink[QuantityArray, paclet:ref/QuantityArray]) representation:

{{Quantity[1,"Seconds"],Quantity[3,"Newtons"]},{Quantity[2,"Seconds"],Quantity[8,"Newtons"]}}

QuantityArray[%]

OpenersExampleSection1(Spacer1)Scope  (7)

Construct an array of quantities with the same unit:

QuantityArray[RandomReal[1,{10,3}],"Meters"]

Convert a normal array of quantities with the same unit:

QuantityArray[{Quantity[1,"Meters"],Quantity[2,"Meters"],Quantity[3,"Meters"]}]

Construct an array of tuples of quantities with different units:

QuantityArray[RandomReal[1,{10,8,3}],{"Meters","Seconds","Kilograms"}]

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

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:

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

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

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 (RefLink[IndependentUnit, paclet:ref/IndependentUnit]) specifications:

QuantityArray[Range[10],IndependentUnit["myUnit"]]

Convert an array of (RefLink[Quantity, paclet:ref/Quantity]) objects into a (RefLink[QuantityArray, paclet:ref/QuantityArray]) expression:

qs={{Quantity[1.,"Kilograms"],Quantity[2.,"Newtons"]},{Quantity[5.,"Kilograms"],Quantity[10.,"Newtons"]},{Quantity[3.,"Kilograms"],Quantity[6.,"Newtons"]}}

QuantityArray[qs]

(RefLink[QuantityArray, paclet:ref/QuantityArray])[…] returns a (RefLink[StructuredArray, paclet:ref/StructuredArray]) object of structure type (RefLink[QuantityArray, paclet:ref/QuantityArray]):

QuantityArray[{10,27,13},"Meters"]

%//InputForm

(RefLink[StructuredArray, paclet:ref/StructuredArray]) objects include properties that give information about the array:

qa=QuantityArray[RandomReal[1,{10,2}],{"Seconds","Meters"}]

qa["Properties"]

This structured array has structure type (RefLink[QuantityArray, paclet:ref/QuantityArray]):

qa["StructureSymbol"]

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

qa["Summary"]

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

qa["StructuredAlgorithms"]

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

qa["Magnitudes"]

qa["UnitBlock"]

OpenersExampleSection4(Spacer1)Properties & Relations  (8)

A (RefLink[QuantityArray, paclet:ref/QuantityArray]) object is interpreted as an array of (RefLink[Quantity, paclet:ref/Quantity]) objects:

qa=QuantityArray[RandomReal[1,{20,2}],{"Meters","Seconds"}]

It is an array:

ArrayQ[qa]

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

MatrixQ[qa]

VectorQ[qa]

It is an array of (RefLink[Quantity, paclet:ref/Quantity]) objects, not an array of numbers:

MatrixQ[qa,QuantityQ]

MatrixQ[qa,NumericQ]

The (RefLink[QuantityArray, paclet:ref/QuantityArray]) representation is memory efficient:

qa=QuantityArray[RandomReal[1,{100,100,2}],{"Meters","Seconds"}]

nqa=Normal[qa,StructuredArray];

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

ByteCount[qa]/ByteCount[nqa]//N

It also allows faster extraction of magnitudes and units:

QuantityMagnitude[qa];//AbsoluteTiming

QuantityUnit[qa];//AbsoluteTiming

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

QuantityMagnitude[nqa];//AbsoluteTiming

QuantityUnit[nqa];//AbsoluteTiming

A single quantity is automatically converted into a (RefLink[Quantity, paclet:ref/Quantity]) object:

QuantityArray[7,"Meters"]

%//InputForm

This is a list with one quantity:

QuantityArray[{7},"Meters"]

%//Normal

It can also be given as:

QuantityArray[{7},{"Meters"}]

%//Normal

During conversion, (RefLink[QuantityArray, paclet:ref/QuantityArray]) does not try to change units:

QuantityArray[{Quantity[1,"Meters"],Quantity[2,"Feet"]}]

(RefLink[UnitConvert, paclet:ref/UnitConvert]) will unify the units:

UnitConvert[%,"Meters"]

Normal[%]

The (RefLink[QuantityArray, paclet:ref/QuantityArray]) structure is preserved in multiple operations. Take two arrays:

qa=QuantityArray[{{1,20},{3,40},{5,60},{7,50}},{"Meters","Seconds"}]

qb=QuantityArray[{{10,2},{20,2},{30,2},{40,2}},{"Feet","Seconds"}]

Addition of (RefLink[QuantityArray, paclet:ref/QuantityArray]) objects of compatible units, automatically converting some of them:

qa+qb

Multiplication of (RefLink[QuantityArray, paclet:ref/QuantityArray]) objects of compatible dimensions:

qa qb

Tensor product of (RefLink[QuantityArray, paclet:ref/QuantityArray]) objects:

TensorProduct[qa,qb]

Transposition is special because it stores the permutation:

Transpose[qa]

%//InputForm

Flattening is also special in that sense:

Flatten[qa]

%//InputForm

Partition the array:

Partition[qa,2]

%//InputForm

Flatten it again:

Flatten[%%,1]

The result is an equivalent, but not identical, representation of the original quantity array:

%==qa

%%===qa

Take a (RefLink[QuantityArray, paclet:ref/QuantityArray]) object with compatible but different units:

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

(RefLink[CommonUnits, paclet:ref/CommonUnits]) will convert it into a single unit array:

CommonUnits[qa]

Normal[%]

To select the unit, use (RefLink[UnitConvert, paclet:ref/UnitConvert]):

UnitConvert[qa,"Meters"]

Normal[%]

A (RefLink[QuantityArray, paclet:ref/QuantityArray]) object of infinite precision:

qa=QuantityArray[{{1,2},{3,4}},{"Meters","Seconds"}]

Precision[qa]

Numericize to precision 20:

nqa=N[qa,20]

Precision[nqa]

InputForm[nqa]

The arithmetic operations take precision into account:

Precision[2. qa]

(RefLink[QuantityArray, paclet:ref/QuantityArray]) will automatically attempt to interpret an unknown unit string:

QuantityArray[RandomReal[1,10],"foot"]

QuantityArray[{{1,20},{3,40},{5,60},{7,50}},{"fps","Meterss"}]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Quantity, paclet:ref/Quantity])  ▪  (RefLink[Normal, paclet:ref/Normal])  ▪  (RefLink[MapThread, paclet:ref/MapThread])  ▪  (RefLink[QuantityMagnitude, paclet:ref/QuantityMagnitude])  ▪  (RefLink[QuantityUnit, paclet:ref/QuantityUnit])  ▪  (RefLink[UnitConvert, paclet:ref/UnitConvert])  ▪  (RefLink[QuantityDistribution, paclet:ref/QuantityDistribution])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Units & Quantities, paclet:guide/Units])}})}})