. Advertisement .
..3..
. Advertisement .
..4..
I am new to python and searching the “valueerror: object too deep for desired array” to understand it better. It seems it doesn’t work as expected when I used some suggestions before. Here is the command line I use:
h = [0.2, 0.2, 0.2, 0.2, 0.2]
Y = np.convolve(Y, h, "same")
The error I’m getting is below:
ValueError: object too deep for desired array
Please give me the solution to this issue.
The cause:
The Y array in your example is a 2D array with 300 rows and 1 column
(300, 1)
, not a 1D array. Whilenp.convolve()
only accepts one-dimensional arrays, not multidimensional arrays, so it throws error “valueerror: object too deep for desired array”.Solution:
You can cut the array as
Y[:, 0]
to get rid of the extra dimension. Usenp.reshape(a, a.size)
to generally convert multidimensional array to 1D. Theflatten()
function from thenumpy.ndarray
module is another alternative for converting a 2D array to a 1D array. However, the difference that it creates a copy of the array.np.convolve()
can only accept one dimension arrays It is necessary to verify the input and convert it into one dimension.To convert an array to one dimension, you can use
np.ravel()
.