# 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 • 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 allclose all

## Basic Examples(3)

A list of lengths, all given in meters:

Extract its magnitudes and units separately:

Normalize the quantity array:

A list of pairs {time,length}:

Extract its magnitudes and units separately:

Convert units:

Convert a normal array of quantities into a QuantityArray representation:

## Scope(6)

Construct an array of quantities with the same unit:

Convert a normal array of quantities with the same unit:

Construct an array of tuples of quantities with different units:

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

Construct an array of matrices of quantities with different units:

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

Construct an array of quantities with IndependentUnit specifications:

Convert an array of Quantity objects into a QuantityArray expression:

QuantityArray objects include properties that give information about the array:

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

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

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

## Properties & Relations(8)

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

It is an array:

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

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

The QuantityArray representation is memory efficient:

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

It also allows faster extraction of magnitudes and units:

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

A single quantity is automatically converted into a Quantity object:

This is a list with one quantity:

It can also be given as:

During conversion, QuantityArray does not try to change units:

UnitConvert will unify the units:

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

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

Multiplication of QuantityArray objects of compatible dimensions:

Tensor product of QuantityArray objects:

Transposition is special because it stores the permutation:

Flattening is also special in that sense:

Partition the array:

Flatten it again:

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

Take a QuantityArray object with compatible but different units:

CommonUnits will convert it into a single unit array:

To select the unit, use UnitConvert:

A QuantityArray object of infinite precision:

Numericize to precision 20:

The arithmetic operations take precision into account:

QuantityArray will automatically attempt to interpret an unknown unit string:

## Possible Issues(1)

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

Specify that only the QuantityArray structure should be normalized: