Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Numpy 类型错误:can';t将序列乘以类型为'的非整数;浮动';,谢谢_Numpy - Fatal编程技术网

Numpy 类型错误:can';t将序列乘以类型为'的非整数;浮动';,谢谢

Numpy 类型错误:can';t将序列乘以类型为'的非整数;浮动';,谢谢,numpy,Numpy,首先将计算分成几行 TypeError: can't multiply sequence by non-int of type 'float' #mark:C_n,R_n,S_n are arraies in 2 dimension 据我所知,这两种计算都是相同的,res如下 Right_item_2 = (1/2)*np.array([ (-1/2)*[ # Here you multiply a list by (-1/2). Should it be ( not [

首先将计算分成几行

TypeError: can't multiply sequence by non-int of type 'float'
#mark:C_n,R_n,S_n are arraies in 2 dimension
据我所知,这两种计算都是相同的,
res
如下

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
计算更具可读性,减少重复性

为什么[],
[(C_n[0,j]…
?确保最后一行是正确的,一步一步。错误表明您已经创建了一个列表,并试图将其乘以一个浮点数,例如
1/2
[/code>创建一个列表。
()
只需将数学表达式分组。不要混淆两者。这是一些非常模糊且不可读的代码。肯定有更好的方法来实现这一点,对吗?似乎有很多重复,可能有一种方法可以使用循环重写。
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 = (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]