Polynomials as a numpy datatype
Project description
Numpoly is a generic library for creating, manipulating polynomial arrays.
Many numerical analysis, prominent in for example uncertainty quantification, uses polynomial approximations as proxy for real models to do analysis on. These models are often solutions to non-linear problems discretized with high mesh. As such, the corresponding polynomial approximation consist of high number of dimensions and large multi-dimensional polynomial coefficients.
numpoly is a subclass of numpy.ndarray implemented to represent polynomials as array element. As such is fast and scales very well with the size of the coefficients. It is also compatible with most numpy functions, where that makes sense, making the interface fairly intuitive. Some of the interface is also inspired by the sympy interface.
Installation
Installation should be straight forward:
pip install numpoly
And you should be ready to go.
Example usage
Constructing polynomial is typically done using one of the available constructors:
>>> numpoly.monomial(start=0, stop=3, indeterminants=("x", "y"))
polynomial([1, y, x, y**2, x*y, x**2, y**3, x*y**2, x**2*y, x**3])
It is also possible to construct your own from symbols:
>>> x, y = numpoly.symbols("x y")
>>> numpoly.polynomial([1, x**2-1, x*y, y**2-1])
polynomial([1, -1+x**2, x*y, -1+y**2])
Or in combination with other numpy objects:
>>> x**numpy.arange(4)-y**numpy.arange(3, -1, -1)
polynomial([1-y**3, x-y**2, x**2-y, -1+x**3])
The polynomials can be evaluated as needed:
>>> poly = 3*x+2*y+1
>>> poly(x=y, y=[1, 2, 3])
polynomial([3+3*y, 5+3*y, 7+3*y])
The polynomials also support many numpy operations:
>>> numpy.reshape(x**numpy.arange(4), (2, 2))
polynomial([[1, x],
[x**2, x**3]])
>>> numpy.sum(numpoly.monomial(12)[::3])
polynomial(1+q**3+q**6+q**9+q**12)
There are also several polynomial specific operators:
>>> numpoly.diff([1, x, x**2], x)
polynomial([0, 1, 2*x])
>>> numpoly.gradient([x*y, x+y])
polynomial([[y, 1],
[x, 1]])
Development
Development is done using Poetry manager. Inside the repository directory, install and create a virtual enviroment with:
poetry install
To run tests, run:
poentry run pytest numpoly test --doctest-modules
Questions & Troubleshooting
For any problems and questions you might have related to numpoly, please feel free to file an issue.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for numpoly-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53c6ecdb5875046eacb9d02d2181d4d70f5bf761ac1cdbc30f9133e39a9e59da |
|
MD5 | a17a9adf538efa638ff22f56ef49691b |
|
BLAKE2b-256 | 847609656e9f6c1834314795f5e857a2aadafbaa29e77fa2c9fba229599905e0 |