def lamb_0(x):
return (1-x)/2
def lamb_1(x):
return (1+x)/2
x = np.array([0.5773502691896257645091488,-0.5773502691896257645091488])
Right_item_2 = (1/2)*np.array([(-1/2)*[(C_n[0,j]*lamb_0(x[0])+C_n[1,j]*lamb_1(x[0]))*(R_n[0,j]*lamb_0(x[0])+R_n[1,j]*lamb_1(x[0]))+(C_n[0,j]*lamb_0(x[1])+C_n[1,j]*lamb_1(x[1]))*(R_n[0,j]*lamb_0(x[1])+R_n[1,j]*lamb_1(x[1]))],(1/2)*[(C_n[0,j]*lamb_0(x[0])+C_n[1,j]*lamb_1(x[0]))*(R_n[0,j]*lamb_0(x[0])+R_n[1,j]*lamb_1(x[0]))+(C_n[0,j]*lamb_0(x[1])+C_n[1,j]*lamb_1(x[1]))*(R_n[0,j]*lamb_0(x[1])+R_n[1,j]*lamb_1(x[1]))]],dtype=float)
TypeError: can't multiply sequence by non-int of type 'float'
#mark:C_n,R_n,S_n are arraies in 2 dimension
答案 0 :(得分:0)
首先将计算分为几行。
detector.isOperational();
据我所知,两种计算方法是相同的,下面的Right_item_2 = (1/2)*np.array([
(-1/2)*[ # Here you multiply a list by (-1/2). Should it be ( not [?
(C_n[0,j]*lamb_0(x[0])+C_n[1,j]*lamb_1(x[0]))*
(R_n[0,j]*lamb_0(x[0])+R_n[1,j]*lamb_1(x[0]))+
(C_n[0,j]*lamb_0(x[1])+C_n[1,j]*lamb_1(x[1]))*
(R_n[0,j]*lamb_0(x[1])+R_n[1,j]*lamb_1(x[1]))
],
(1/2)*[ # Here you multiply a list by (-1/2)
(C_n[0,j]*lamb_0(x[0])+C_n[1,j]*lamb_1(x[0]))*
(R_n[0,j]*lamb_0(x[0])+R_n[1,j]*lamb_1(x[0]))+
(C_n[0,j]*lamb_0(x[1])+C_n[1,j]*lamb_1(x[1]))*
(R_n[0,j]*lamb_0(x[1])+R_n[1,j]*lamb_1(x[1]))
]
],dtype=float)
。
res
仍有使res = (C_n[0,j]*lamb_0(x[0])+C_n[1,j]*lamb_1(x[0]))*
(R_n[0,j]*lamb_0(x[0])+R_n[1,j]*lamb_1(x[0]))+
(C_n[0,j]*lamb_0(x[1])+C_n[1,j]*lamb_1(x[1]))*
(R_n[0,j]*lamb_0(x[1])+R_n[1,j]*lamb_1(x[1]))
Right_itm_2 = np.array[-.5*res, .5*res]
计算更易读,更不重复的范围