import numpy as np
from pint import UnitRegistry
unit = UnitRegistry()
Q_ = unit.Quantity
a = 1.0*unit.meter
b = 2.0*unit.meter
# some calculations that change a and b
x=np.array([a.magnitude,b.magnitude])*Q_(1.0,a.units)
将从变量 a 和 b 中创建一个 numpy 数组,这些变量是品脱数量。这有点粗略,因为不能保证 a 和 b 具有相同的单位。有更清洁的方法吗?我需要写一个函数吗?