2
b, a = butter(order, normal_cutoff, btype='low', analog=False)
  • this highlights butter, and says there are too many values to unpack. When I run the code, it works and returns no errors.
b, a, c = butter(order, normal_cutoff, btype='low', analog=False)
  • this is not highlighted, but when I run the code it breaks because it expects 3 outputs from butter, but only is getting 2.

I feel this is weird because I should not be getting any error in the first case but it is still shouting at me about too many values... so I give it more values to output and it breaks my code. Any insight?

Woodford
  • 3,746
  • 1
  • 15
  • 29
  • *"this highlights butter"* *What* highlights butter? Presumably your IDE/editor? Which one are you using? What does it use for syntax highlighting and detecting the number of return values? Whatever it is, I suspect it is confused by the description of the return values in the [`butter`](http://scipy.github.io/devdocs/reference/generated/scipy.signal.butter.html) docstring, which describes three different sets of return values, the meaning of which depends on the `output` parameter. – Warren Weckesser Sep 02 '21 at 21:00
  • pycharm is my ide – Joe Baltzly Sep 03 '21 at 12:54

1 Answers1

0

The return values of butter are dependent upon the output function parameter, which defaults to 'ba'. Whatever is "highlighting" your code isn't taking into account the variable nature of the output values which explains why the code runs correctly.

The documentation clearly describes the different return values possible:

>>> help(scipy.signal.butter)
Help on function butter in module scipy.signal.filter_design:

butter(N, Wn, btype='low', analog=False, output='ba', fs=None)
    Butterworth digital and analog filter design.
...
    Returns
    -------
    b, a : ndarray, ndarray
        Numerator (`b`) and denominator (`a`) polynomials of the IIR filter.
        Only returned if ``output='ba'``.
    z, p, k : ndarray, ndarray, float
        Zeros, poles, and system gain of the IIR filter transfer
        function.  Only returned if ``output='zpk'``.
    sos : ndarray
        Second-order sections representation of the IIR filter.
        Only returned if ``output=='sos'``.
Woodford
  • 3,746
  • 1
  • 15
  • 29