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

Issues with using numpy arrays of Quantities indexing and inplace operations #498

Open
alexfeld opened this issue Apr 6, 2017 · 2 comments
Labels
numpy Numpy related bug/enhancement

Comments

@alexfeld
Copy link

alexfeld commented Apr 6, 2017

I often need to store arrays of variables that have different units, e.g. when solving a system of equations. I've noticed some inconsistent behavior with several operations. Note below that Qx is an instance of a quantity, not necessarily with the same units

f = np.empty(3, dtype=object)
x = np.array([1., 2])
f[[0,1]] = x * Q   # f now contains the magnitude of x*Q, not the quantities as I would expect

y = np.array([Q1, Q2, Q3], dtype=object)
y *= Q4  # the magnitude changes correctly but the units do not. The units of the divisor are lost and the units of the original quantities are preserved

These issues can be mitigated using loops and indexing but it would be nice if these operations were supported.

@hgrecco
Copy link
Owner

hgrecco commented May 3, 2017

It seems that numpy is taking precedence over the pint to execute this code. Maybe there is a work around. I need to take a closer look

@hgrecco
Copy link
Owner

hgrecco commented Dec 3, 2019

Revisit after #905

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
numpy Numpy related bug/enhancement
Projects
None yet
Development

No branches or pull requests

2 participants