Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add support for symbol to polynomial package (#16154)
Adds a symbol attribute to the polynomials from the np.polynomial package to allow the user to control/modify the symbol used to represent the independent variable for a polynomial expression. This attribute corresponds to the variable attribute of the poly1d class from the old np.lib.polynomial module. Marked as draft for now as it depends on #15666 - all _str* and _repr* methods of ABCPolyBase and derived classes would need to be modified (and tested) to support this change. Co-authored-by: Warren Weckesser <warren.weckesser@gmail.com>
- Loading branch information
1 parent
07709f3
commit b84a53d
Showing
6 changed files
with
420 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
New attribute ``symbol`` added to polynomial classes | ||
---------------------------------------------------- | ||
|
||
The polynomial classes in the ``numpy.polynomial`` package have a new | ||
``symbol`` attribute which is used to represent the indeterminate | ||
of the polynomial. | ||
This can be used to change the value of the variable when printing:: | ||
|
||
>>> P_y = np.polynomial.Polynomial([1, 0, -1], symbol="y") | ||
>>> print(P_y) | ||
1.0 + 0.0·y¹ - 1.0·y² | ||
|
||
Note that the polynomial classes only support 1D polynomials, so operations | ||
that involve polynomials with different symbols are disallowed when the | ||
result would be multivariate:: | ||
|
||
>>> P = np.polynomial.Polynomial([1, -1]) # default symbol is "x" | ||
>>> P_z = np.polynomial.Polynomial([1, 1], symbol="z") | ||
>>> P * P_z | ||
Traceback (most recent call last) | ||
... | ||
ValueError: Polynomial symbols differ | ||
|
||
The symbol can be any valid Python identifier. The default is ``symbol=x``, | ||
consistent with existing behavior. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.