numpoly.ndpoly¶
- class numpoly.ndpoly(exponents: Union[numpy._typing._array_like._SupportsArray[numpy.dtype], numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy._typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]] = ((0)), shape: Tuple[int, ...] = (), names: Union[None, str, Tuple[str, ...], ndpoly] = None, dtype: Union[numpy.dtype[Any], None, Type[Any], numpy._typing._dtype_like._SupportsDType[numpy.dtype[Any]], str, Tuple[Any, int], Tuple[Any, Union[SupportsIndex, Sequence[SupportsIndex]]], List[Any], numpy._typing._dtype_like._DTypeDict, Tuple[Any, Any]] = None, allocation: Optional[int] = None, **kwargs: Any)[source]¶
Polynomial as numpy array.
An array object represents a multidimensional, homogeneous polynomial array of fixed-size items. An associated data-type object describes the format of each element in the array (its byte-order, how many bytes it occupies in memory, whether it is an integer, a floating point number, or something else, etc.)
Though possible, it is not recommended to construct polynomials using
ndpoly
for basic polynomial array construction. Instead the user should be consider using construction functions like variable, monomial, polynomial, etc.- Example:
>>> poly = ndpoly( ... exponents=[(0, 1), (0, 0)], shape=(3,)) >>> poly.values[";<"] = 4, 5, 6 >>> poly.values[";;"] = 1, 2, 3 >>> numpy.array(poly.coefficients) array([[4, 5, 6], [1, 2, 3]]) >>> poly polynomial([4*q1+1, 5*q1+2, 6*q1+3]) >>> poly[0] polynomial(4*q1+1)
- __init__()¶
Initialize self. See help(type(self)) for accurate signature.
- __call__(*args: PolyLike, **kwargs: PolyLike) → Union[numpy.ndarray, ndpoly][source]¶
Evaluate polynomial by inserting new values in to the indeterminants.
- Args:
- args:
Argument to evaluate indeterminants. Ordered positional by
self.indeterminants
.- kwargs:
Same as
args
, but positioned by name.
- Return:
Evaluated polynomial. If the resulting array does not contain any indeterminants, an array is returned instead of a polynomial.
- Example:
>>> q0, q1 = numpoly.variable(2) >>> poly = numpoly.polynomial( ... [[q0, q0-1], [q1, q1+q0]]) >>> poly(1, q1=[0, 1, 2]) array([[[1, 1, 1], [0, 0, 0]], [[0, 1, 2], [1, 2, 3]]])
Methods
from_attributes
(exponents, coefficients[, …])Construct polynomial from polynomial attributes.
Check if a polynomial is constant or not.
todict
()Cast to dict where keys are exponents and values are coefficients.
tonumpy
()Cast polynomial to numpy.ndarray, if possible.
Attributes
Polynomial coefficients.
Datatype of the polynomial coefficients.
Polynomial exponents.
Polynomial indeterminants.
The raw names of the coefficients.
Same as indeterminants, but only the names as string.
Expose the underlying structured array.
Internal number off-set between exponent and its stored value.