Difference (subtraction) of two polynomials. .. note:: This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in `numpy.polynomial` is preferred. A summary of the differences can be found in the :doc:`transition guide </refe
(a1, a2)
| 855 | |
| 856 | @array_function_dispatch(_binary_op_dispatcher) |
| 857 | def polysub(a1, a2): |
| 858 | """ |
| 859 | Difference (subtraction) of two polynomials. |
| 860 | |
| 861 | .. note:: |
| 862 | This forms part of the old polynomial API. Since version 1.4, the |
| 863 | new polynomial API defined in `numpy.polynomial` is preferred. |
| 864 | A summary of the differences can be found in the |
| 865 | :doc:`transition guide </reference/routines.polynomials>`. |
| 866 | |
| 867 | Given two polynomials `a1` and `a2`, returns ``a1 - a2``. |
| 868 | `a1` and `a2` can be either array_like sequences of the polynomials' |
| 869 | coefficients (including coefficients equal to zero), or `poly1d` objects. |
| 870 | |
| 871 | Parameters |
| 872 | ---------- |
| 873 | a1, a2 : array_like or poly1d |
| 874 | Minuend and subtrahend polynomials, respectively. |
| 875 | |
| 876 | Returns |
| 877 | ------- |
| 878 | out : ndarray or poly1d |
| 879 | Array or `poly1d` object of the difference polynomial's coefficients. |
| 880 | |
| 881 | See Also |
| 882 | -------- |
| 883 | polyval, polydiv, polymul, polyadd |
| 884 | |
| 885 | Examples |
| 886 | -------- |
| 887 | .. math:: (2 x^2 + 10 x - 2) - (3 x^2 + 10 x -4) = (-x^2 + 2) |
| 888 | |
| 889 | >>> np.polysub([2, 10, -2], [3, 10, -4]) |
| 890 | array([-1, 0, 2]) |
| 891 | |
| 892 | """ |
| 893 | truepoly = (isinstance(a1, poly1d) or isinstance(a2, poly1d)) |
| 894 | a1 = atleast_1d(a1) |
| 895 | a2 = atleast_1d(a2) |
| 896 | diff = len(a2) - len(a1) |
| 897 | if diff == 0: |
| 898 | val = a1 - a2 |
| 899 | elif diff > 0: |
| 900 | zr = NX.zeros(diff, a1.dtype) |
| 901 | val = NX.concatenate((zr, a1)) - a2 |
| 902 | else: |
| 903 | zr = NX.zeros(abs(diff), a2.dtype) |
| 904 | val = a1 - NX.concatenate((zr, a2)) |
| 905 | if truepoly: |
| 906 | val = poly1d(val) |
| 907 | return val |
| 908 | |
| 909 | |
| 910 | @array_function_dispatch(_binary_op_dispatcher) |
no test coverage detected