Skip to main content

A package providing an unit system for numpy multidimensionnal arrays.

Project description

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.

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 github.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
    • ...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

numpy_unit-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

numpy_unit-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file numpy_unit-0.1.0.tar.gz.

File metadata

  • Download URL: numpy_unit-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for numpy_unit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ca57b0e52324aaddc4a8622862d9c25fc6d2b1cb2c1dc7d33bf0c43773709e95
MD5 1f49e9a3276f540522ffc41de650f588
BLAKE2b-256 a2ff78848e5b6e2680ad27956e5203de4f4236c3c4ef8f0ec231cbfc77820cc6

See more details on using hashes here.

File details

Details for the file numpy_unit-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: numpy_unit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for numpy_unit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 289c4315f924ff5d20a3780bf9eb2f478a461eb8e8080c333060392511324647
MD5 2abc50818db4bf73390fff3e9b442647
BLAKE2b-256 80901ed28d0ffc31d9fc486b697aee4ac540bbb7ec9f8fccde84d0b47a06d695

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page