Quantity ======== The `Quantity` object is meant to represent a value that has some unit associated with the number. Creating Quantity instances --------------------------- `Quantity` objects are created through multiplication or divison with `Unit` objects. For example, to create a `Quantity` to represent :math:`15\frac{m}{s}` >>> import astropy.units as u >>> 15*u.m/u.s or :math:`1.14s^{-1}` >>> 1.14/u.s You can also create instances using the `Quantity` constructor directly, by specifying a value and unit >>> u.Quantity(15, u.m/u.s) Arithmetic ---------- Addition and Subtraction ~~~~~~~~~~~~~~~~~~~~~~~~ Addition or subtraction between `Quantity` objects is supported when their units are equivalent (see `Unit` documentation). When the units are equal, the resulting object has the same unit >>> 11*u.s + 30*u.s >>> 30*u.s - 11*u.s If the units are equivalent, but not equal (e.g. kilometer and meter), the resulting object **has units of the object on the left** >>> 1100.1*u.m + 13.5*u.km >>> 13.5*u.km + 1100.1*u.m >>> 1100.1*u.m - 13.5*u.km >>> 13.5*u.km - 1100.1*u.m Addition and subtraction is not supported between `Quantity` objects and basic numeric types >>> 13.5*u.km + 19.412 TypeError: Object of type '' cannot be added with a Quantity object. Addition is only supported between Quantity objects. Multiplication and Division ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Multiplication and division is supported between `Quantity` objects with any units, and with numeric types. For these operations between objects with equivalent units, the **resulting object has composite units** >>> 1.1*u.m * 140.3*u.cm >>> 140.3*u.cm * 1.1*u.m >>> 1.*u.m / (20.*u.cm) >>> 20.*u.cm / (1.*u.m) For multiplication, you can choose how to represent the resulting object by using the `~astropy.units.quantity.Quantity.to` method >>> (1.1*u.m * 140.3*u.cm).to(u.m**2) >>> (1.1*u.m * 140.3*u.cm).to(u.cm**2) For division, if the units are equivalent, you may want to make the resulting object dimensionless by reducing the units. To do this, use the `.simplify_units()` method >>> (20.*u.cm / (1.*u.m)).simplify_units() This method is also useful for more complicated arithmetic >>> 15.*u.kg * 32.*u.cm * 15*u.m / (11.*u.s * 1914.15*u.ms) >>> (15.*u.kg * 32.*u.cm * 15*u.m / (11.*u.s * 1914.15*u.ms)).simplify_units()