问题描述
我最近开始使用 Python,在尝试解决下一个三重集成时发现了我的第一个问题:
到目前为止,我使用了以下语法:
from numpy import cos,pi
from scipy import integrate
f = lambda x,y,z: x**2 * y * (cos * (pi * z) + 2 )
x1,x2 = 0,3
y1,y2 = 0,2
z1,z2 = 0,5
integrate.tplquad(f,x1,x2,y1,y2,z1,z2 )
主要错误似乎如下:
TypeError: unsupported operand type(s) for *: 'numpy.ufunc' and 'float'
如果您有任何回应,我将不胜感激:)
解决方法
在您的函数定义中,您需要删除 *
之后的 cos
,因为 cos()
是一个函数,因此它与括号中的参数一起使用。