我将哪个整数误认为是数组? (“ int”对象没有属性“ __getitem__”)

我在python中得到错误

TypeError: 'int' object has no attribute '__getitem__'

I know that this means that somewhere I am applying apply the index operator [] on an int and not a list, but I don't know where?

def p1(p,a,b):
    result1=1
    result2=1
    for i in np.arange(0,p-1):
        result1=result1*Tarray[i]
    for i in np.arange(p,147):
        result2=result2*Tarray[i]
    return np.sum(result1[n,a]*Tarray[p-1][a,b]*result2[b,m] for n in range(4) for m in range(4))

u=np.arange(1,4)
Pro=np.vectorize(p1)

print Pro(u,0,0)

Here Tarray is an array of 147 numerical 4x4-matrices.

The odd thing is that when I plug in a numerical value for p, the p1 works perfectly fine.

评论