make_interp_spline(x, y[1:151])(x_smooth) ValueError: x and y are incompatible.

created at 01-31-2022 views: 10


Traceback (most recent call last):
  File "E:/Program Files/PyCharm 2019.2/GraduationDesign/", line 193, in <module>
    test(name, B)
  File "E:/Program Files/PyCharm 2019.2/GraduationDesign/", line 180, in test
    y_smooth = make_interp_spline(x, y[1:151])(x_smooth)
  File "F:\Anaconda3\lib\site-packages\scipy\interpolate\", line 795, in make_interp_spline
    raise ValueError('x and y are incompatible.')
ValueError: x and y are incompatible.


The corresponding code in the original text is:

x = [i for i in range(1, 151)]
x_smooth = np.linspace(np.min(x), np.max(x), 900)
y_smooth = make_interp_spline(x, y[150:300])(x_smooth)

The error message x and y are incompatible obviously does not mean that the lengths of x and y are inconsistent, but that the shape is inconsistent: the shape of y is (150, 1), which requires Transpose it:

y_smooth = make_interp_spline(x, y.T[150:300])(x_smooth)
created at:01-31-2022
edited at: 01-31-2022: