Python:TypeError:float()参数必须是字符串或数字,而不是';功能';

Python:TypeError:float()参数必须是字符串或数字,而不是';功能';,python,Python,我在Jupyter网站上工作,下面是我的代码 def get_hist(img, bins): histogram = np.zeros(bins) for pixel in im: histogram[pixel] += 1 return get_hist hist = get_hist(flat, 256) plt.plot(hist) 我一直都有这个问题 TypeError: float() argument must be a strin

我在Jupyter网站上工作,下面是我的代码

def get_hist(img, bins):
    histogram = np.zeros(bins)

    for pixel in im:
        histogram[pixel] += 1

    return get_hist

hist = get_hist(flat, 256)

plt.plot(hist)
我一直都有这个问题

TypeError: float() argument must be a string or a number, not 'function'

有什么有用的建议吗?

您编写了一个返回自己函数对象的函数。这不会提供太多的功能或可用性。您可能需要返回
直方图
,这似乎是您的函数想要做的。

您应该执行
返回直方图
,而不是
返回历史
。非常感谢。你的评论真的帮了我的忙!那么我能再问你一个问题吗?非常感谢。我可以再问你一个关于Python的问题吗?@Liz最好为你的每个问题提交一个新问题,这样它就为其他人和社区提供了最大的价值。哦,好的。我刚刚加入了stack overflow,对此我一无所知!我将提交一个新问题:)谢谢!