我有一个计算成本相对较高的函数,给定单个标量后返回一个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()
有没有一种方法可以一次性集成整个数组,或者我需要逐个元素进行集成?我想避免第二种解决方案,因为没有简单的方法来计算数组中的一个元素。
scipy.integrate.romberg
内部发生的,而不是我的代码。我可以将其作为补丁贡献,但如果有更正式的集成数组的方法,我想这样做。 - Chris Granade