Numpoly is a generic library for creating, manipulating and evaluating
arrays of polynomials based on numpy.ndarray objects.
Table of Contents:
- Intuitive interface for users experienced with
numpy, as the library provides a high level of compatibility with thenumpy.ndarray, including fancy indexing, broadcasting,numpy.dtype, vectorized operations to name a few. - Computationally fast evaluations of lots of functionality inherent from
numpy. - Vectorized polynomial evaluation.
- Support for arbitrary number of dimensions.
- Native support for lots of
numpy.<name>functions usingnumpy's compatibility layer (which also exists asnumpoly.<name>equivalents). - Support for polynomial division through the operators
/,%anddivmod. - Extra polynomial specific attributes exposed on the polynomial objects like
poly.exponents,poly.coefficients,poly.indeterminantsetc. - Polynomial derivation through functions like
numpoly.derivative,numpoly.gradient,numpoly.hessianetc. - Decompose polynomial sums into vector of addends using
numpoly.decompose. - Variable substitution through
numpoly.call.
Installation should be straight forward:
pip install numpolyConstructing polynomial is typically done using one of the available constructors:
>>> import numpoly
>>> numpoly.monomial(start=0, stop=3, dimensions=2)
polynomial([1, q0, q0**2, q1, q0*q1, q1**2])It is also possible to construct your own from symbols together with numpy:
>>> import numpy
>>> q0, q1 = numpoly.variable(2)
>>> numpoly.polynomial([1, q0**2-1, q0*q1, q1**2-1])
polynomial([1, q0**2-1, q0*q1, q1**2-1])Or in combination with numpy objects using various arithmetics:
>>> q0**numpy.arange(4)-q1**numpy.arange(3, -1, -1)
polynomial([-q1**3+1, -q1**2+q0, q0**2-q1, q0**3-1])The constructed polynomials can be evaluated as needed:
>>> poly = 3*q0+2*q1+1
>>> poly(q0=q1, q1=[1, 2, 3])
polynomial([3*q1+3, 3*q1+5, 3*q1+7])Or manipulated using various numpy functions:
>>> numpy.reshape(q0**numpy.arange(4), (2, 2))
polynomial([[1, q0],
[q0**2, q0**3]])
>>> numpy.sum(numpoly.monomial(13)[::3])
polynomial(q0**12+q0**9+q0**6+q0**3+1)