本文整理汇总了Python中pint.context.Context.add_transformation方法的典型用法代码示例。如果您正苦于以下问题:Python Context.add_transformation方法的具体用法?Python Context.add_transformation怎么用?Python Context.add_transformation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pint.context.Context
的用法示例。
在下文中一共展示了Context.add_transformation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_arg_ctxs
# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import add_transformation [as 别名]
def add_arg_ctxs(ureg):
a, b = UnitsContainer({'[length]': 1}), UnitsContainer({'[time]': -1})
d = Context('lc')
d.add_transformation(a, b, lambda ureg, x, n: ureg.speed_of_light / x / n)
d.add_transformation(b, a, lambda ureg, x, n: ureg.speed_of_light / x / n)
ureg.add_context(d)
a, b = UnitsContainer({'[length]': 1}), UnitsContainer({'[current]': -1})
d = Context('ab')
d.add_transformation(a, b, lambda ureg, x: 1 / x)
d.add_transformation(b, a, lambda ureg, x: 1 / x)
ureg.add_context(d)
示例2: add_sharedargdef_ctxs
# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import add_transformation [as 别名]
def add_sharedargdef_ctxs(ureg):
a, b = UnitsContainer({"[length]": 1}), UnitsContainer({"[time]": -1})
d = Context("lc", defaults=dict(n=1))
assert d.defaults == dict(n=1)
d.add_transformation(a, b, lambda ureg, x, n: ureg.speed_of_light / x / n)
d.add_transformation(b, a, lambda ureg, x, n: ureg.speed_of_light / x / n)
ureg.add_context(d)
a, b = UnitsContainer({"[length]": 1}), UnitsContainer({"[current]": 1})
d = Context("ab", defaults=dict(n=0))
d.add_transformation(a, b, lambda ureg, x, n: ureg.ampere * ureg.meter * n / x)
d.add_transformation(b, a, lambda ureg, x, n: ureg.ampere * ureg.meter * n / x)
ureg.add_context(d)
示例3: add_argdef_ctxs
# 需要导入模块: from pint.context import Context [as 别名]
# 或者: from pint.context.Context import add_transformation [as 别名]
def add_argdef_ctxs(ureg):
a, b = UnitsContainer({'[length]': 1}), UnitsContainer({'[time]': -1})
d = Context('lc', defaults=dict(n=1))
assert d.defaults == dict(n=1)
d.add_transformation(a, b, lambda ureg, x, n: ureg.speed_of_light / x / n)
d.add_transformation(b, a, lambda ureg, x, n: ureg.speed_of_light / x / n)
ureg.add_context(d)
a, b = UnitsContainer({'[length]': 1}), UnitsContainer({'[current]': 1})
d = Context('ab')
d.add_transformation(a, b, lambda ureg, x: ureg.ampere * ureg.meter / x)
d.add_transformation(b, a, lambda ureg, x: ureg.ampere * ureg.meter / x)
ureg.add_context(d)