如何解决Scipy quad 函数 ValueError:具有多个元素的数组的真值不明确使用 a.any() 或 a.all()
我有一个函数利润(x),它是从 0 到 x 的“某物”的积分。 给定 y,我试图找到值 x,以便使利润(x)=y。
问题是在 quad 函数上引发了 ValueError
。我不明白我做错了什么,因为我可以使用相同的函数进行基本计算。例如:
quad(profit,5)[0]
12.5
代码如下:
x = np.linspace(0,60,10000)
def profit(x):
return x
res,err = quad(profit,60)
print('Integral profit:',res,'error:',err)
积分利润:1800.0000000000002 错误:1.998401444325282e-11
profit_cut = res / 2
print(profit_cut)
900.0000000000001
x_value = np.interp(profit_cut,quad(profit,x)[0],x)
x_value
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-79-d879688713aa> in <module>
----> 1 x_value = np.interp(profit_cut,xmin,x)
2 x_value
~\AppData\Local\Continuum\anaconda3\lib\site-packages\scipy\integrate\quadpack.py in quad(func,a,b,args,full_output,epsabs,epsrel,limit,points,weight,wvar,wopts,maxp1,limlst)
346
347 # check the limits of integration: \int_a^b,expect a < b
--> 348 flip,b = b < a,min(a,b),max(a,b)
349
350 if weight is None:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
你知道是什么导致了这种情况吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。