【发布时间】:2010-11-05 20:58:21
【问题描述】:
我有一个相对昂贵的计算函数,给定一个标量,它返回一个 numpy.array() 对象。当我尝试使用 scipy.integrate.romberg 将这个函数与标量参数集成时,我从 scipy 用于确定收敛的条件中得到一个内部错误:
Traceback (most recent call last):
File "wqc.py", line 148, in <module>
H_cycle = (m.pi / wt) * scipy.integrate.romberg(H_if, 0, m.pi / wt)
File "/usr/lib/python2.6/site-packages/scipy/integrate/quadrature.py", line 471, in romberg
while (abs(result - lastresult) > tol) and (i <= divmax):
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
有没有办法一次整合整个数组,还是需要逐个元素整合?我想避免第二种解决方案,因为没有简单的方法可以计算 仅 数组的一个元素。
【问题讨论】: