Detailed description |
|
I recently ran into a problem involving Quantity objects wrapping numpy arrays interacting with un-wrapped numpy numbers. Observe:
>>> import numpy
>>> import simtk.unit as units
>>> x = numpy.float32(1.0)
>>> y = units.Quantity(numpy.ones([3], numpy.float64), units.kilocalories_per_mole)
>>> x / y[0]
1.0
# Wait a second...that should have units!
# Note that there's no problem if the Quantity is not wrapping a numpy array:
>>> z = 1.0 * units.kilocalories_per_mole
>>> x / z
Quantity(value=1.0, unit=mole/kilocalorie)
# But interacting with standard Python floats is fine:
>>> w = 1.0
>>> w / y[0]
Quantity(value=1.0, unit=mole/kilocalorie)
|
|