my code is:
import numpy as np
import scipy.io as spio
x=np.zeros((22113,1),float)
x= spio.loadmat('C:\\Users\\dell\\Desktop\\Rabia Ahmad spring 2016\\'
'FYP\\1. Matlab Work\\record work\\kk.mat')
print(x)
x = np.reshape(len(x),1);
h = np.array([0.9,0.3,0.1],float)
print(h)
h = h.reshape(len(h),1);
dd = np.convolve(h,x)
and the error I encounter is " ValueError: object too deep for desired array " kindly help me in this reguard.
{'__globals__': [], '__version__': '1.0', 'ans': array([[ 0.13580322,
0.13580322], [ 0.13638306, 0.13638306], [ 0.13345337, 0.13345337],
..., [ 0.13638306, 0.13638306], [ 0.13345337, 0.13345337], ..., [
0.13638306, 0.13638306], [ 0.13345337, 0.13345337], ..., [-0.09136963,
-0.09136963], [-0.12442017, -0.12442017], [-0.15542603, -0.15542603]])}
See {}? That means x
from the loadmat
is a dictionary.
x['ans']
will be an array
array([[ 0.13580322,
0.13580322], [ 0.13638306, 0.13638306], [ 0.13345337, 0.13345337],...]])
which, if I count the [] right is a (n,2) array of floats.
The following line does not make sense:
x = np.reshape(len(x),1);
I suspect you mean x = x.reshape(...)
as you do with h
. But that would give an error with the dictionary x
.
When you say the shape of x is (9,) and its dtype is uint16
- where in your code you verifying that?
x = np.reshape(len(x),1);
doesn't do anything useful. That completely discards the data in x, and creates an array of shape (1,)
, with the only element being len(x)
.
In your code, you reshape h
to (3, 1)
, which is a 2D array, not a 1D array, which is why convolve
complains.
Remove both of your reshape
s, and instead just pass squeeze=True
to scipy.io.loadmat
- this is needed because matlab does not have the concept as 1d arrays, and squeeze tells scipy to try and flatten (N, 1)
and (1, N)
arrays to (N,)
arrays
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.