Polynomials as a numpy datatype
Project description
Numpoly is a generic library for creating, manipulating polynomial arrays.
numpoly is a subclass of numpy.ndarray and as such is compatible with most numpy functions, where that makes sense.
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:
>>> poly1 = numpoly.monomial(("x", "y"), start=0, stop=3)
>>> print(poly1)
[1 y x x*y x**2 y**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")
>>> poly2 = numpoly.polynomial([1, x**2-1, x*y, y**2-1])
>>> print(poly2)
[1 -1+x**2 x*y -1+y**2]
Or in combination with other numpy objects:
>>> poly3 = x**numpy.arange(4)-y**numpy.arange(3, -1, -1)
>>> print(poly3)
[1-y**3 -y**2+x -y+x**2 -1+x**3]
The polynomials can be evaluated as needed:
>>> print(poly1(1, 2))
[1 2 1 2 1 4 8 4 2 1]
>>> print(poly2(x=[1, 2]))
[[1 1]
[0 3]
[y 2*y]
[-1+y**2 -1+y**2]]
>>> print(poly1(x=y, y=2*x))
[1 2*x y 2*x*y y**2 4*x**2 8*x**3 4*x**2*y 2*x*y**2 y**3]
The polynomials also support many numpy operations:
>>> print(numpy.reshape(poly2, (2, 2)))
[[1 -1+x**2]
[x*y -1+y**2]]
>>> print(poly1[::3].astype(float))
[1.0 x*y y**3 x**3]
>>> print(numpy.sum(poly1.reshape(2, 5), 0))
[1+y**2 y+y**3 x+x*y**2 x*y+x**2*y x**2+x**3]
There are also several polynomial specific operators:
>>> print(numpoly.diff(poly3, y))
[-3*y**2 -2*y -1 0]
>>> print(numpoly.gradient(poly3))
[[0 1 2*x 3*x**2]
[-3*y**2 -2*y -1 0]]
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.0.7-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44d9ff5ace35f35058956717bcea244bcca05b97bb2c86e349db36587885843c |
|
MD5 | fd1bd33c009625c1a10092b9c01587aa |
|
BLAKE2b-256 | 135369e849da1965b46cc3d121b28894d3366af15b5e66b5ea5305dcdeaa2483 |