Quantity

class astropy.units.quantity.Quantity(value, unit) [edit on github][source]

Bases: object

A Quantity represents a number with some associated unit.

Parameters :

value : number

The numerical value of this quantity in the units given by unit.

unit : UnitBase instance, str

An object that represents the unit associated with the input value. Must be an UnitBase object or a string parseable by the units package.

Raises :

TypeError :

If the value provided is not a Python numeric type.

TypeError :

If the unit provided is not either a Unit object or a parseable string unit.

Attributes Summary

isscalar True if the value of this quantity is a scalar, or False if it is an array-like object.
unit A UnitBase object representing the unit of this quantity.
decomposed_unit Generates a new Quantity with the units decomposed.
cgs Returns a copy of the current Quantity instance with CGS units.
value The numerical value of this quantity.
si Returns a copy of the current Quantity instance with SI units.

Methods Summary

to(unit) Returns a new Quantity object with the specified units.
copy() Return a copy of this Quantity instance

Attributes Documentation

isscalar[source]

True if the value of this quantity is a scalar, or False if it is an array-like object.

Note

This is subtly different from numpy.isscalar in that numpy.isscalar returns False for a zero-dimensional array (e.g. np.array(1)), while this is True in that case.

unit[source]

A UnitBase object representing the unit of this quantity.

decomposed_unit[source]

Generates a new Quantity with the units decomposed. Decomposed units have only irreducible units in them (see astropy.units.UnitBase.decompose).

Returns :

newq : Quantity

A new object equal to this quantity with units decomposed.

cgs[source]

Returns a copy of the current Quantity instance with CGS units. The value of the resulting object will be scaled.

value[source]

The numerical value of this quantity.

si[source]

Returns a copy of the current Quantity instance with SI units. The value of the resulting object will be scaled.

Methods Documentation

to(unit) [edit on github][source]

Returns a new Quantity object with the specified units.

Parameters :

unit : UnitBase instance, str

An object that represents the unit to convert to. Must be an UnitBase object or a string parseable by the units package.

copy() [edit on github][source]

Return a copy of this Quantity instance

Page Contents