"ValueError: x and y must not be None"什么



我试图使用以下代码在两点之间找到函数 f(z( 的积分:

z = np.linspace(0,1,100)
def f(z): 
return z**2
times = 2000
x=np.random.rand(times)
y=np.random.rand(times)
under = y <= x**2
N1 = np.cumsum(under)
N1_over_N = (N1/np.arange(1,times + 1, dtype=np.float))
def integral(arr):
(1-0)*(f(1)-f(0))*arr

fig1 = plt.figure()
fig1.set_size_inches(5, 5)
plt.plot(x,y,'o',markersize = 1)
plt.plot(integral(N1_over_N) )
plt.show()

我不断收到"ValueError:x 和 y 不得为 None"。我不知道这是什么意思,我在任何地方都找不到它的参考。你能帮忙吗? 谢谢

您的函数积分缺少返回语句:

def integral(arr)
return (1-0)*(f(1)-f(0))*arr

这应该会让你得到你的情节。 虽然函数目前没有做太多(1 * 1 * arr(,你可能想看看scipy集成函数。

相关内容

最新更新