astropy:docs

Quantity

class astropy.units.quantity.Quantity[source] [edit on github]

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[source]

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

equivalencies[source]

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

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.

si[source]

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

unit[source]

A UnitBase object representing the unit of this quantity.

value[source]

The numerical value of this quantity.

Methods Documentation

all(axis=None, out=None)[source] [edit on github]
any(axis=None, out=None)[source] [edit on github]
argmax(axis=None, out=None)[source] [edit on github]
argmin(axis=None, out=None)[source] [edit on github]
argsort(axis=-1, kind=u'quicksort', order=None)[source] [edit on github]
choose(choices, out=None, mode=u'raise')[source] [edit on github]
clip(a_min, a_max, out=None)[source] [edit on github]
copy()[source] [edit on github]

Return a copy of this Quantity instance

cumprod(axis=None, dtype=None, out=None)[source] [edit on github]
cumsum(axis=None, dtype=None, out=None)[source] [edit on github]
decompose(bases=[])[source] [edit on github]

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)[source] [edit on github]
dot(b, out=None)[source] [edit on github]
dump(file)[source] [edit on github]
dumps()[source] [edit on github]
ediff1d(to_end=None, to_begin=None)[source] [edit on github]
fill(value)[source] [edit on github]
item(*args)[source] [edit on github]
itemset(*args)[source] [edit on github]
list()[source] [edit on github]
max(axis=None, out=None, keepdims=False)[source] [edit on github]
mean(axis=None, dtype=None, out=None)[source] [edit on github]
min(axis=None, out=None, keepdims=False)[source] [edit on github]
nansum(axis=None)[source] [edit on github]
prod(axis=None, dtype=None, out=None, keepdims=False)[source] [edit on github]
ptp(axis=None, out=None)[source] [edit on github]
put(indices, values, mode=u'raise')[source] [edit on github]
searchsorted(v, *args, **kwargs)[source] [edit on github]
std(axis=None, dtype=None, out=None, ddof=0)[source] [edit on github]
sum(axis=None, dtype=None, out=None, keepdims=False)[source] [edit on github]
to(unit, equivalencies=[])[source] [edit on github]

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')[source] [edit on github]
tostring(order=u'C')[source] [edit on github]
trace(offset=0, axis1=0, axis2=1, dtype=None, out=None)[source] [edit on github]
var(axis=None, dtype=None, out=None, ddof=0)[source] [edit on github]

Page Contents