Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Measurements, Uncertainties, and Arrays #1665

Open
SamG-01 opened this issue Nov 26, 2022 · 2 comments
Open

Measurements, Uncertainties, and Arrays #1665

SamG-01 opened this issue Nov 26, 2022 · 2 comments

Comments

@SamG-01
Copy link

SamG-01 commented Nov 26, 2022

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)
@vasilisniaouris
Copy link

I am having the same issue! Is there any intention to add this functionality?

@vasilisniaouris
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants