首页 > 解决方案 > Python:TypeError:float() 参数必须是字符串或数字,而不是“函数”

问题描述

我在 Jupyter Web 上工作,下面是我的代码。

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

解决方案


您编写了一个返回它自己的函数对象的函数。这不会提供太多功能或可用性。您可能需要 return histogram,这似乎是您的功能打算做的事情。


推荐阅读