函数中的Numpy数组

2024-06-18 10:25:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用numpy数组做一个函数作为参数。你知道吗

我有以下代码:

def Q_aux(j,theta,phi,cm,binom):  

    suma = 0.0 + 0.0j    

    for m in range(-j,j+1):
        for n in range (-j,j+1):
            suma += cm[j+m] * cm[j+n] * sp.sqrt(binom[j+m]*binom[j+n]) * pow(sp.tan(theta/2.0), 2*j+m+n) * cmt.polar(phi*(n-m))

    return suma / pow(1+pow(sp.tan(theta/2.0),2.0), 4.0*j)

其中binomcm都是一维数组。例如,我已经检查了我是否可以使用cm[4]访问(和操作)它的元素。spcmt分别是SciPy和Cmath。你知道吗

但是,该函数给了我以下错误:

unsupported operand type(s) for +=: 'complex' and 'tuple'

为什么会出现这种错误?我怎样才能避免呢?我在网上读了很多东西,真不知道该怎么办。你知道吗


Tags: 函数infor错误cmrange数组sp