Last active
May 3, 2016 23:47
-
-
Save alpha-beta-soup/0350c21c054d3bc0f23d8ddd8c857ed1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pint | |
ur = pint.UnitRegistry() | |
Q = ur.Quantity | |
def convert(array, source, target): | |
''' | |
Convert a list in one unit to a list in another, using Pint. | |
Simple but saves me from writing this repeatedly in ipython. | |
<source> and <target> must be Pint units, e.g. | |
>>> ur = pint.UnitRegistry() | |
>>> convert([1, 2], ur.inch, ur.meter) | |
[<Quantity(0.0254, 'meter')>, <Quantity(0.0508, 'meter')>] | |
''' | |
return [Q(x, source).to(target) for x in array] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment