ValueError: object too deep for desired array while using convolution

前端 未结 4 1358
既然无缘
既然无缘 2020-12-15 15:24

I\'m trying to do this:

h = [0.2,0.2,0.2,0.2,0.2]

Y = np.convolve(Y, h, \"same\")

Y looks like this:

相关标签:
4条回答
  • np.convolve needs a flattened array as one of it's inputs, you can use numpy.ndarray.flatten() which is quite fast, find it here.

    0 讨论(0)
  • 2020-12-15 15:52

    The Y array in your screenshot is not a 1D array, it's a 2D array with 300 rows and 1 column, as indicated by its shape being (300, 1).

    To remove the extra dimension, you can slice the array as Y[:, 0]. To generally convert an n-dimensional array to 1D, you can use np.reshape(a, a.size).

    Another option for converting a 2D array into 1D is flatten() function from numpy.ndarray module, with the difference that it makes a copy of the array.

    0 讨论(0)
  • 2020-12-15 16:05

    You could try using scipy.ndimage.convolve it allows convolution of multidimensional images. here is the docs

    0 讨论(0)
  • 2020-12-15 16:06

    np.convolve() takes one dimension array. You need to check the input and convert it into 1D.

    You can use the np.ravel(), to convert the array to one dimension.

    0 讨论(0)
提交回复
热议问题