Polynomials as a numpy datatype
Project description
Numpoly is a generic library for creating, manipulating and evaluating arrays of polynomials.
The polynomial base class numpoly.ndpoly is a subclass of numpy.ndarray implemented to represent polynomials as array element. This makes the library very fast with the respect of the size of the coefficients. It is also adds compatibility with numpy functions and methods, where that makes sense, making the interface more intuitive.
Many numerical analysis, polynomial approximations as proxy predictors for real predictors to do analysis on. These models are often solutions to nonlinear problems discretized with high mesh. As such, the corresponding polynomial approximation consist of high number of dimensions and large multidimensional polynomial coefficients. For these kind of problems numpoly is a good fit.
One example where numpoly is used as the backend is the uncertainty quantification library chaospy.
Table of Contents:
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=4, names=("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**21, x*y, y**21]) polynomial([1, 1+x**2, x*y, 1+y**2])
Or in combination with numpy objects using various arithmetics:
>>> x**numpy.arange(4)y**numpy.arange(3, 1, 1) polynomial([1y**3, xy**2, x**2y, 1+x**3])
The constructed 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])
Or manipulated using various numpy functions:
>>> numpy.reshape(x**numpy.arange(4), (2, 2)) polynomial([[1, x], [x**2, x**3]]) >>> numpy.sum(numpoly.monomial(13, names="z")[::3]) polynomial(1+z**3+z**6+z**9+z**12)
In addition there are also several operators specific to the polynomial:
>>> 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 environment with:
poetry install
To run tests, run:
poentry run pytest numpoly test doc doctestmodules
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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Filename, size  File type  Python version  Upload date  Hashes 

Filename, size numpoly0.1.6py2.py3noneany.whl (75.7 kB)  File type Wheel  Python version py2.py3  Upload date  Hashes View hashes 
Filename, size numpoly0.1.6.tar.gz (41.7 kB)  File type Source  Python version None  Upload date  Hashes View hashes 
Hashes for numpoly0.1.6py2.py3noneany.whl
Algorithm  Hash digest  

SHA256  452aeda55c7c8555950ea3b8adc9196281b3913c147c550be2b50e8b14285004 

MD5  5dd8ebf2d7efbb6a05c09c4f94d3b5be 

BLAKE2256  26fe1fed381444c4133bf31f785d76a44588670914280a1ae45eb9d21515ff71 