Python中报错提示TypeError: ‘function’ object is not subscriptable
在构建一个矩阵时,最后一列为了得到一个值全为1的矩阵使用了如下代码:
np.hstack(a,b,np.ones[n,1])
得到报错:TypeError: ‘function’ object is not subscriptable
由于实际代码里a,b写得比较复杂,一直以为是前面的a,b出了错。
仔细检查发现,错误来源于np.ones([n,1])
上网查了资料后的总结:
TypeError: 'function' object is not subscriptable
一般由于函数没有正确使用括号