You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to build an array with Measurements 1 +/- 0.1 km, 2 +/- 0.1 km, and 3 +/- 0.1 km. I start with the list [1, 2, 3] and the error 0.1, so I try to make a Measurement object:
from pint import UnitRegistry
ureg = UnitRegistry()
n = [1, 2, 3]
s = 0.1
x1 = ureg.Measurement(n, s, ureg.km)
However, this returns an error AttributeError: 'list' object has no attribute 'strip' from uncertainties/core.py.
Other than a manual loop
import numpy as np
x2 = np.array([ureg.Measurement(val, s, ureg.km) for val in n])
, the only way to get something close (but not quite sufficient) is to create a Quantity instead (see #1614):
import uncertainties.unumpy as unp
x3 = ureg.Quantity(unp.uarray(n, s), ureg.km)
The text was updated successfully, but these errors were encountered:
I followed the error. It turns out that Measurement in pint only defines a ufloat. In order to remove this error, you need to define the Measurement with an uncertainty.unumpy.uarray instead. I am not sure what the correct pint-ian(?) way of implementing an uncertainty.unumpy.uarray would be.
Related side-note: There is another error raised if you add a list of std_dev instead of a single std_dev : ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() That comes from the if error < 0: ... line, which could be replaced by if np.any(error < 0): ... to alleviate the issue.
I want to build an array with Measurements 1 +/- 0.1 km, 2 +/- 0.1 km, and 3 +/- 0.1 km. I start with the list
[1, 2, 3]
and the error0.1
, so I try to make a Measurement object:However, this returns an error
AttributeError: 'list' object has no attribute 'strip'
fromuncertainties/core.py
.Other than a manual loop
, the only way to get something close (but not quite sufficient) is to create a Quantity instead (see #1614):
The text was updated successfully, but these errors were encountered: