Traceback (most recent call last):
File "C:\Users\Ian\Downloads\main_stereo.py", line 56, in <module>
leftCh = myconv(leftimp, waveData) # convolution of left ear impulse response and waveData
File "C:\Users\Ian\Downloads\my_conv.py", line 34, in myconv
z=[0]*len_h+x
ValueError: operands could not be broadcast together with shapes (40001) (128)
我的卷积是什么给了麻烦,它给了我上面的错误,我不能为我的生活弄清楚我做错了什么
mycon.py
import numpy as np
def myconv(x,h):
# INPUT PARAMETERS---------------------------------------------------------
# x: input signal
# h: impulse response
这是函数的输入:
我相信是一个数组
[ 5.94000000e+02 -7.70000000e+02 9.75000000e+02 -1.17400000e+03
1.32740000e+04 1.02210000e+04 -2.80010000e+04 -1.13600000e+03
1.43450000e+04 -9.92000000e+02 3.42200000e+03 2.17110000e+04
1.11780000e+04 -1.48470000e+04 2.62200000e+03 1.03150000e+04
1.48400000e+03 -3.60800000e+03 -3.51100000e+03 -5.28700000e+03
-1.33000000e+03 4.20000000e+02 -4.47000000e+03 -3.88100000e+03
-3.54200000e+03 -8.05000000e+02 -1.83300000e+03 -1.08700000e+03
9.00000000e+02 -2.83000000e+02 -1.31000000e+02 -9.43000000e+02
-1.33000000e+03 -2.49000000e+03 -1.04400000e+03 -1.73100000e+03
-1.56700000e+03 -1.36500000e+03 -2.01500000e+03 -1.20100000e+03
-1.08500000e+03 -6.01000000e+02 -7.44000000e+02 -2.92000000e+02
-9.61000000e+02 -9.57000000e+02 -8.16000000e+02 -7.85000000e+02
-2.51000000e+02 -4.10000000e+01 -4.42000000e+02 -4.09000000e+02
-1.54000000e+02 6.70000000e+01 1.70000000e+01 -3.55000000e+02
-6.34000000e+02 -6.22000000e+02 -6.10000000e+02 -5.62000000e+02
-2.04000000e+02 -3.24000000e+02 -2.85000000e+02 -4.50000000e+02
-2.13000000e+02 -3.50000000e+01 -4.50000000e+01 7.50000000e+01
7.10000000e+01 -1.02000000e+02 -1.84000000e+02 -2.09000000e+02
-2.30000000e+02 -4.60000000e+01 9.80000000e+01 -7.30000000e+01
-2.02000000e+02 -7.90000000e+01 4.00000000e+00 8.00000000e+00
9.00000000e+00 6.60000000e+01 -6.40000000e+01 -5.40000000e+01
-8.60000000e+01 -7.80000000e+01 5.30000000e+01 1.08000000e+02
4.10000000e+01 -6.20000000e+01 -2.00000000e+02 -1.26000000e+02
-2.00000000e+00 1.30000000e+02 1.93000000e+02 8.40000000e+01
-1.20000000e+02 -2.74000000e+02 -9.30000000e+01 7.70000000e+01
1.26000000e+02 -1.50000000e+01 -5.60000000e+01 -1.26000000e+02
-1.17000000e+02 1.20000000e+01 7.20000000e+01 7.20000000e+01
-4.20000000e+01 -1.14000000e+02 -1.22000000e+02 3.00000000e+00
1.61000000e+02 2.00000000e+02 1.43000000e+02 5.30000000e+01
5.00000000e+01 1.75000000e+02 2.10000000e+02 1.92000000e+02
1.31000000e+02 9.20000000e+01 7.50000000e+01 1.20000000e+02
1.87000000e+02 1.69000000e+02 1.15000000e+02 9.10000000e+01]
这是另一个数组:
[-0.00985718 -0.00982666 -0.00912476 ..., 0.00064087 0.00015259
-0.00061035]
答案 0 :(得分:1)
您无法混合np.arrays()
和列表。您应该写[0]*len_h+x
而不是np.zeros(len_h) + np.asarray(x)
。澄清:
import numpy as np
a = [1,2,3]
np_a = np.array(a)
print(a+a) # gives [1,2,3,1,2,3]
print(np_a + np_a) # gives[2,4,6] of type np.array()