[python] ValueError: object too deep for desired array while using convolution

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:

screenshot

While doing this I get this error:

ValueError: object too deep for desired array

Why is this?

My guess is because somehow the convolve function does not see Y as a 1D array.

This question is related to python numpy convolution valueerror

The answer is


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


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.


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.


Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to numpy

Unable to allocate array with shape and data type How to fix 'Object arrays cannot be loaded when allow_pickle=False' for imdb.load_data() function? Numpy, multiply array with scalar TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array Could not install packages due to a "Environment error :[error 13]: permission denied : 'usr/local/bin/f2py'" Pytorch tensor to numpy array Numpy Resize/Rescale Image what does numpy ndarray shape do? How to round a numpy array? numpy array TypeError: only integer scalar arrays can be converted to a scalar index

Examples related to convolution

ValueError: object too deep for desired array while using convolution

Examples related to valueerror

sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype('float64') ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle? ValueError: shape mismatch: objects cannot be broadcast to a single shape ValueError: object too deep for desired array while using convolution