flopscope.

flopscope.numpy.polyadd

Find the sum of two polynomials.

Adapted from NumPy docs np.polyadd

Areacore
Typecustom
NumPy Refnp.polyadd
Cost
numel(polyadd(a1,a2))\text{numel}(\text{polyadd}(a_1, a_2))
Flopscope Context

Add two polynomials. Cost: size of the axis-0 zero-padded, broadcast-aligned add result (== numpy.polyadd(a1, a2).size; reduces to max(n1, n2) for 1-D inputs).

Note.

This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in flops.polynomial is preferred. A summary of the differences can be found in the transition guide.

Returns the polynomial resulting from the sum of two input polynomials. Each input must be either a poly1d object or a 1D sequence of polynomial coefficients, from highest to lowest degree.

Parameters

a1, a2:array_like or poly1d object

Input polynomials.

Returns

out:ndarray or poly1d object

The sum of the inputs. If either input is a poly1d object, then the output is also a poly1d object. Otherwise, it is a 1D array of polynomial coefficients from highest to lowest degree.

See also

Examples

>>> import flopscope.numpy as fnp
>>> flops.polyadd([1, 2], [9, 5, 4])
array([9, 6, 6])

Using poly1d objects:

>>> p1 = flops.poly1d([1, 2])
>>> p2 = flops.poly1d([9, 5, 4])
>>> print(p1)
1 x + 2
>>> print(p2)
   2
9 x + 5 x + 4
>>> print(flops.polyadd(p1, p2))
   2
9 x + 6 x + 6