astro py:docs

- Index
- Modules

### Navigation

- next »
- « previous |
- Astropy v0.3 »
- Units and Quantities (`astropy.units`) »
- Quantity

# Quantity

class `astropy.units.quantity.``Quantity`

  Bases: `numpy.ndarray`

  A `Quantity` represents a number with some associated unit.

  Parameters:

  value : number, `Quantity` object, or sequence of `Quantity` objects.

  > The numerical value of this quantity in the units given by unit. If a `Quantity` or sequence of them, creates a new `Quantity` object, converting to `unit` units as needed.

  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.

  dtype : ~numpy.dtype, optional

  > The dtype of the resulting Numpy array or scalar that will hold the value. If not provided, is is determined automatically from the input value.

  copy : bool, optional

  > If `True` (default), then the value is copied. Otherwise, a copy will only be made if `__array__` returns a copy, if obj is a nested sequence, or if a copy is needed to satisfy `dtype`. (The `False` option is intended mostly for internal use, to speed up initialization where it is known a copy has been made already. Use with care.)

  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

  `cgs` | Returns a copy of the current `Quantity` instance with CGS units.
  `equivalencies` | A list of equivalencies that will be applied by default during unit conversions.
  `isscalar` | True if the `value` of this quantity is a scalar, or False if it is an array-like object.
  `si` | Returns a copy of the current `Quantity` instance with SI units.
  `unit` | A `UnitBase` object representing the unit of this quantity.
  `value` | The numerical value of this quantity.

  Methods Summary

  `all`([axis, out]) |
  `any`([axis, out]) |
  `argmax`([axis, out]) |
  `argmin`([axis, out]) |
  `argsort`([axis, kind, order]) |
  `choose`(choices[, out, mode]) |
  `clip`(a_min, a_max[, out]) |
  `copy`() | Return a copy of this `Quantity` instance
  `cumprod`([axis, dtype, out]) |
  `cumsum`([axis, dtype, out]) |
  `decompose`([bases]) | Generates a new `Quantity` with the units decomposed.
  `diff`([n, axis]) |
  `dot`(b[, out]) |
  `dump`(file) |
  `dumps`() |
  `ediff1d`([to_end, to_begin]) |
  `fill`(value) |
  `item`(*args) |
  `itemset`(*args) |
  `list`() |
  `max`([axis, out, keepdims]) |
  `mean`([axis, dtype, out]) |
  `min`([axis, out, keepdims]) |
  `nansum`([axis]) |
  `prod`([axis, dtype, out, keepdims]) |
  `ptp`([axis, out]) |
  `put`(indices, values[, mode]) |
  `searchsorted`(v, *args, **kwargs) |
  `std`([axis, dtype, out, ddof]) |
  `sum`([axis, dtype, out, keepdims]) |
  `to`(unit[, equivalencies]) | Returns a new `Quantity` object with the specified units.
  `tofile`(fid[, sep, format]) |
  `tostring`([order]) |
  `trace`([offset, axis1, axis2, dtype, out]) |
  `var`([axis, dtype, out, ddof]) |

  Attributes Documentation

  `cgs`

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

  `equivalencies`

    A list of equivalencies that will be applied by default during unit conversions.

  `isscalar`

    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.

  `si`

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

  `unit`

    A `UnitBase` object representing the unit of this quantity.

  `value`

    The numerical value of this quantity.

  Methods Documentation

  `all`(axis=None, out=None)
  `any`(axis=None, out=None)
  `argmax`(axis=None, out=None)
  `argmin`(axis=None, out=None)
  `argsort`(axis=-1, kind=u'quicksort', order=None)
  `choose`(choices, out=None, mode=u'raise')
  `clip`(a_min, a_max, out=None)
  `copy`()

    Return a copy of this `Quantity` instance

  `cumprod`(axis=None, dtype=None, out=None)
  `cumsum`(axis=None, dtype=None, out=None)
  `decompose`(bases=[])

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

    Parameters:

    bases : sequence of UnitBase, optional

    > The bases to decompose into. When not provided, decomposes down to any irreducible units. When provided, the decomposed result will only contain the given units. This will raises a `UnitsError` if it’s not possible to do so.

    Returns:

    newq : `Quantity`

    > A new object equal to this quantity with units decomposed.

  `diff`(n=1, axis=-1)
  `dot`(b, out=None)
  `dump`(file)
  `dumps`()
  `ediff1d`(to_end=None, to_begin=None)
  `fill`(value)
  `item`(*args)
  `itemset`(*args)
  `list`()
  `max`(axis=None, out=None, keepdims=False)
  `mean`(axis=None, dtype=None, out=None)
  `min`(axis=None, out=None, keepdims=False)
  `nansum`(axis=None)
  `prod`(axis=None, dtype=None, out=None, keepdims=False)
  `ptp`(axis=None, out=None)
  `put`(indices, values, mode=u'raise')
  `searchsorted`(v, *args, **kwargs)
  `std`(axis=None, dtype=None, out=None, ddof=0)
  `sum`(axis=None, dtype=None, out=None, keepdims=False)
  `to`(unit, equivalencies=[])

    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.

    equivalencies : list of equivalence pairs, optional

    > A list of equivalence pairs to try if the units are not directly convertible. See Equivalencies. If not provided or `[]`, class default equivalencies will be used (none for `Quantity`, but may be set for subclasses) If `None`, no equivalencies will be applied at all, not even any set globally or within a context.

  `tofile`(fid, sep=u'', format=u'%s')
  `tostring`(order=u'C')
  `trace`(offset=0, axis1=0, axis2=1, dtype=None, out=None)
  `var`(axis=None, dtype=None, out=None, ddof=0)