Quantity¶

class
simtk.unit.quantity.
Quantity
(value=None, unit=None)¶ Physical quantity, such as 1.3 meters per second.
Quantities contain both a value, such as 1.3; and a unit, such as ‘meters per second’.
 Supported value types include:
1  numbers (float, int, long) 2  lists of numbers, e.g. [1,2,3] 3  tuples of numbers, e.g. (1,2,3)
Note  unit conversions will cause tuples to be converted to lists4  lists of tuples of numbers, lists of lists of ... etc. of numbers 5  numpy.arrays

__init__
(value=None, unit=None)¶ Create a new Quantity from a value and a unit.
 Parameters
 value: (any type, usually a number) Measure of this quantity
 unit: (Unit) the physical unit, e.g. simtk.unit.meters.
Methods
__init__
([value, unit])Create a new Quantity from a value and a unit. append
(item)count
(item)extend
(rhs)format
(format_spec)in_unit_system
(system)Returns a new Quantity equal to this one, expressed in a particular unit system. in_units_of
(other_unit)Returns an equal Quantity expressed in different units. index
(item)insert
(index, item)max
(*args, **kwargs)Computes the maximum value of the sequence, with the result having the same unit as the current sequence. mean
(*args, **kwargs)Computes the mean of a sequence, with the result having the same unit as the current sequence. min
(*args, **kwargs)Computes the minimum value of the sequence, with the result having the same unit as the current sequence. pop
(*args)reduce_unit
([guide_unit])Combine similar component units and scale, to form an equal Quantity in simpler units. remove
(item)reshape
(shape[, order])Same as numpy.ndarray.reshape, except the result is a Quantity with the sqrt
()Returns square root of a Quantity. std
(*args, **kwargs)Computes the square root of the variance of a sequence, with the result having the same unit as the current sequence. sum
(*args, **kwargs)Computes the sum of a sequence, with the result having the same unit as the current sequence. value_in_unit
(unit)Returns underlying value, in the specified units. value_in_unit_system
(system)Returns the underlying value type, after conversion to a particular unit system. 
__copy__
()¶ Shallow copy produces a new Quantity with the shallow copy of value and the same unit. Because we want copy operations to work just the same way they would on the underlying value.

__deepcopy__
(memo)¶ Deep copy produces a new Quantity with a deep copy of the value, and the same unit. Because we want copy operations to work just the same way they would on the underlying value.

__getattr__
(attribute)¶ Delegate unrecognized attribute calls to the underlying value type.

__str__
()¶ Printable string version of this Quantity.
Returns a string consisting of quantity number followed by unit abbreviation.

__repr__
()¶

__add__
(other)¶ Add two Quantities.
Only Quantities with the same dimensions (e.g. length) can be added. Raises TypeError otherwise.
 Parameters
 self: left hand member of sum
 other: right hand member of sum
Returns a new Quantity that is the sum of the two arguments.

__sub__
(other)¶ Subtract two Quantities.
Only Quantities with the same dimensions (e.g. length) can be subtracted. Raises TypeError otherwise.
 Parameters
 self: left hand member (a) of a  b.
 other: right hand member (b) of a  b.
Returns a new Quantity that is the difference of the two arguments.

__eq__
(other)¶

__ne__
(other)¶

reduce_unit
(guide_unit=None)¶ Combine similar component units and scale, to form an equal Quantity in simpler units.
Returns underlying value type if unit is dimensionless.

__mul__
(other)¶ Multiply a quantity by another object
Returns a new Quantity that is the product of the self * other, unless the resulting unit is dimensionless, in which case the underlying value type is returned, instead of a Quantity.

__rmul__
(other)¶ Multiply a scalar by a Quantity
Returns a new Quantity with the same units as self, but with the value multiplied by other.

__truediv__
(other)¶ Divide a Quantity by another object
Returns a new Quantity, unless the resulting unit type is dimensionless, in which case the underlying value type is returned.

__div__
(other)¶ Divide a Quantity by another object
Returns a new Quantity, unless the resulting unit type is dimensionless, in which case the underlying value type is returned.

__rtruediv__
(other)¶ Divide a scalar by a quantity.
Returns a new Quantity. The resulting units are the inverse of the self argument units.

__rdiv__
(other)¶ Divide a scalar by a quantity.
Returns a new Quantity. The resulting units are the inverse of the self argument units.

__pow__
(exponent)¶ Raise a Quantity to a power.
Generally both the value and the unit of the Quantity are affected by this operation.
Returns a new Quantity equal to self**exponent.

sqrt
()¶ Returns square root of a Quantity.
Raises ArithmeticError if component exponents are not even. This behavior can be changed if you present a reasonable real life case to me.

sum
(*args, **kwargs)¶ Computes the sum of a sequence, with the result having the same unit as the current sequence.
If the value is not iterable, it raises a TypeError (same behavior as if you tried to iterate over, for instance, an integer).
This function can take as arguments any arguments recognized by numpy.sum. If arguments are passed to a nonnumpy array, a TypeError is raised

mean
(*args, **kwargs)¶ Computes the mean of a sequence, with the result having the same unit as the current sequence.
If the value is not iterable, it raises a TypeError
This function can take as arguments any arguments recognized by numpy.mean. If arguments are passed to a nonnumpy array, a TypeError is raised

std
(*args, **kwargs)¶ Computes the square root of the variance of a sequence, with the result having the same unit as the current sequence.
If the value is not iterable, it raises a TypeError
This function can take as arguments any arguments recognized by numpy.std. If arguments are passed to a nonnumpy array, a TypeError is raised

max
(*args, **kwargs)¶ Computes the maximum value of the sequence, with the result having the same unit as the current sequence.
If the value is not iterable, it raises a TypeError
This function can take as arguments any arguments recognized by numpy.max. If arguments are passed to a nonnumpy array, a TypeError is raised

min
(*args, **kwargs)¶ Computes the minimum value of the sequence, with the result having the same unit as the current sequence.
If the value is not iterable, it raises a TypeError
This function can take as arguments any arguments recognized by numpy.min. If arguments are passed to a nonnumpy array, a TypeError is raised

reshape
(shape, order='C')¶ Same as numpy.ndarray.reshape, except the result is a Quantity with the same units as the current object rather than a plain numpy.ndarray

__abs__
()¶ Return absolute value of a Quantity.
The unit is unchanged. A negative value of self will result in a positive value in the result.

__pos__
()¶ Returns a reference to self.

__neg__
()¶ Negate a Quantity.
Returns a new Quantity with a different sign on the value.

__nonzero__
()¶ Returns True if value underlying Quantity is zero, False otherwise.

value_in_unit
(unit)¶ Returns underlying value, in the specified units.

value_in_unit_system
(system)¶ Returns the underlying value type, after conversion to a particular unit system.

in_unit_system
(system)¶ Returns a new Quantity equal to this one, expressed in a particular unit system.

in_units_of
(other_unit)¶ Returns an equal Quantity expressed in different units.
If the units are the same as those in self, a reference to self is returned. Raises a TypeError if the new unit is not compatible with the original unit.
 The post_multiply argument is used in case the multiplication operation is not commutative.
 i.e. result = factor * value when post_multiply is False and result = value * factor when post_multiply is True

__delattr__
¶ x.__delattr__(‘name’) <==> del x.name

__format__
()¶ default object formatter

__getattribute__
¶ x.__getattribute__(‘name’) <==> x.name

__hash__
¶

__reduce__
()¶ helper for pickle

__reduce_ex__
()¶ helper for pickle

__setattr__
¶ x.__setattr__(‘name’, value) <==> x.name = value

__sizeof__
() → int¶ size of object in memory, in bytes

__len__
()¶ Return size of internal value type.

__getitem__
(key)¶ Keep the same units on contained elements.