Python 具有复杂值的Numpy数组分配获取错误:“0”;ComplexWarning:将复数值强制转换为实数将丢弃虚部“;

Python 具有复杂值的Numpy数组分配获取错误:“0”;ComplexWarning:将复数值强制转换为实数将丢弃虚部“;,python,numpy,variable-assignment,complex-numbers,Python,Numpy,Variable Assignment,Complex Numbers,我正试图做这样的手术: width = 23 alpha_i = np.array([1.84704762, 1.7878235 , 1.72701305, 1.66501652, 1.60228591, 1.53930674, 1.47657613, 1.41457961, 1.35376915, 1.29454503]) w_s_i = (wc / c) * d * np.cos(alpha_i) ws_idx = np.zeros((width, 1)) # vettore ch

我正试图做这样的手术:

width = 23
alpha_i = np.array([1.84704762, 1.7878235 , 1.72701305, 1.66501652, 1.60228591,
   1.53930674, 1.47657613, 1.41457961, 1.35376915, 1.29454503])

w_s_i = (wc / c) * d * np.cos(alpha_i) 
ws_idx = np.zeros((width, 1)) # vettore che contiene "width" elementi spaziati di 1
ii = 0
for i in range(np.int(np.floor(width / 2)),-np.int(np.floor(width / 2))-1,-1):
   ws_idx[ii,:] =  i
   ii = ii + 1


# eq.(7)
steer_vecs = np.zeros((width, alpha_i.shape[0]));
   for i in range(0,10):
   steer_vecs[:, i] = np.squeeze(np.exp(1j * np.multiply(ws_idx ,w_s_i[i])),axis=1)
但我不知道为什么在最后一个for循环结束时,虚部会被丢弃。。 我得到以下错误:

ComplexWarning: Casting complex values to real discards the imaginary part

有什么建议吗?谢谢

左侧
steer_vecs[:,i]
是一个类型为
float64
的数组。因此,如果您尝试为浮点数组指定复杂值,则会收到警告

因此,您需要将
steer\u vecs
声明为一个复杂数组:

steer_vecs = np.zeros((width, alpha_i.shape[0]), dtype=np.complex)