numpy-unit
This package provides a tool for scientific computing by keeping track of the unit when performing classical operations on a multi-dimensionnal array with (almost) no extra-cost comparing to the standard numpy array.
The ArrayUnit class supports every operation a numpy.ndarray can handle (because it is a derived class of numpy.ndarray) but the operators are overloaded in order to perform transformations on the Unit contained in every ArrayUnit.
Install
pip install numpy-unit
Examples
>>> import numpy as np
>>> from numpy_unit import Unit, ArrayUnit
>>>
>>> m = Unit('m')
>>> sm2 = Unit('s', -2)
>>> complex_unit = Unit({'my_unit': 0.5, '€': 1, 'capita': 2}) * (sm2**0.5) / m
>>> print(complex_unit)
€·capita²·my_unit^0.5·m⁻¹·s⁻¹
>>>
>>> arr = np.linspace(1,10,10, dtype=float)
>>> a = ArrayUnit(arr, m)
>>> b = ArrayUnit(arr**2, sm2)
>>> print(a, '\\n+\\n', 1, '\\n=\\n', a + 1)
[ 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.] m
+
1
=
[ 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.] m
>>> print(a, '\\n*\\n', b, '\\n=\\n', a * b)
[ 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.] m
*
[ 1. 4. 9. 16. 25. 36. 49. 64. 81. 100.] s⁻²
=
[ 1. 8. 27. 64. 125. 216. 343. 512. 729. 1000.] m·s⁻²
The following rules applied (where {op} is one of the following: [+, -, *, /, //, %]):
- ArrayUnit {op} Object returns an ArrayUnit with the same unit as the ArrayUnit
- Object {op} ArrayUnit returns an ArrayUnit with the same unit as the ArrayUnit
- ArrayUnit {op} ArrayUnit returns an ArrayUnit combining the Unit of the 2 ArrayUnit or an Error
- An Error might be raised only when two ArrayUnit are conflicting and that ArrayUnit.is_strict is set to True. Otherwise, it would print a warning.
- An ArrayUnit is equal to a numpy.ndarray if and only if their underlying arrays are equal (np.array_equal) and the Unit of the ArrayUnit is empty.
Development
Doc of the master branch on readthedocs.io.
Features
- Basic unit system handling multiplication, division, modulo and power
- ArrayUnit wrapper for unit + ndarray
- Operators on ArrayUnit (and their variants r{op} and i{op})
- eq, ne
- add
- sub
- mul
- truediv, floordiv
- mod
- pow (but not rpow)
- Basic ndarray function
- mean
- std
- ...
- conda release
Release files for numpy-unit 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| numpy_unit-0.1.1.tar.gz | 7.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| numpy_unit-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.0 kB
Release files / numpy_unit-0.1.1.tar.gz
| Download URL | numpy_unit-0.1.1.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07935585dfeee8dddcada9ab8ea4209b74e52a1d104f6122ef61583bebaf1b96
|
|
BLAKE2b-256 checksum How to use checksums |
2e63d5c740c83218f67d19635f7056c5b33a5624154434d330f6d4d310939e1e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Release files / numpy_unit-0.1.1-py3-none-any.whl
| Download URL | numpy_unit-0.1.1-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4ca911cc5b17d79c4f1a30aa128703a836c3149939279449ef2342da1dbfd184
|
|
BLAKE2b-256 checksum How to use checksums |
a69626bfcd76332d4357d812bba047ad757640a1f6db2e922282199a2eac2923
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|