A package for handling numpy arrays with units.
Often writing code that deals with data that has units can be confusing. A function might return an array but at least with plain NumPy arrays, there is no way to easily tell what the units of the data are without somehow knowing a priori.
unyt package (pronounced like "unit") provides a subclass of NumPy's
ndarray class that knows about units. For example, one could do:
>>> import unyt as u >>> distance_traveled = [3.4, 5.8, 7.2] * u.mile >>> print(distance_traveled.to('km')) [ 5.4717696 9.3341952 11.5872768] km
And a whole lot more! See the documentation for more examples as well as full API docs.
This package only depends on
six and, on Python 2.7,
backports.functools_lru_cache (a backport of
Notably, it does not depend on
yt and it is written in pure Python.
Code of Conduct
unyt package is part of The yt Project. Participating in
unyt development therefore
happens under the auspices of the yt community code of conduct. If
for any reason you feel that the code of conduct has been violated, please send
an e-mail to [email protected] with details describing the
incident. All emails sent to this address will be treated with the strictest
confidence by an individual who does not normally participate in yt development.
The unyt package is licensed under the BSD 3-clause license.
If you make use of unyt in a publication we would appreciate a mention in the text of the paper or in the acknowledgements.
We have submitted a paper to the
Journal of Open Source Software. A preprint is available on the arxiv. We would
appreciate a citation (BibTeX)
to the paper if you make use of
unyt for work that leads to a publication.