Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eliminate units when using quantities for Python

I'm using the great quantities package for Python. I would like to know how I can get at just the numerical value of the quantity, without the unit.

I.e., if I have

E = 5.3*quantities.joule

I would like to get at just the 5.3. I know I can simply divide by the "undesired" unit, but hoping there was a better way to do this.

like image 870
jlconlin Avatar asked Dec 21 '22 01:12

jlconlin


1 Answers

E.item() seems to be what you want, if you want a Python float. E.magnitude, offered by tzaman, is a 0-dimensional NumPy array with the value, if you'd prefer that.

The documentation for quantities doesn't seem to have a very good API reference.

like image 120
kindall Avatar answered Jan 09 '23 11:01

kindall