harold.haroldpolyadd

harold.haroldpolyadd(*args, trim_zeros=True)

A wrapper around NumPy’s numpy.polyadd() but allows for multiple args and offers a trimming option.

Parameters:
  • args (iterable) – An iterable with 1D array-like elements.
  • trim_zeros (bool, optional) – If True, the zeros at the front of the input and output arrays are truncated. Default is True.
Returns:

p (ndarray) – The polynomial coefficients of the sum.

Examples

>>> a = np.array([2, 3, 5, 8])
>>> b = np.array([1, 3, 4])
>>> c = np.array([6, 9, 10, -8, 6])
>>> haroldpolyadd(a, b, c)
array([ 6., 11., 14.,  0., 18.])
>>> d = np.array([-2, -4 ,3, -1])
>>> haroldpolyadd(a, b, d)
array([ 0.,  0., 11., 11.])
>>> haroldpolyadd(a, b, d, trim_zeros=False)
array([ 0.,  0., 11., 11.])