欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

Python总结:RuntimeError: matplotlib does not support generators as input

发布时间:2024/7/5 python 55 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Python总结:RuntimeError: matplotlib does not support generators as input 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

QUESTION:RuntimeError: matplotlib does not support generators as input?

 

ANSWER:

例子:

来源:stackoverflow:question

在运行github上的一个例子时,https://github.com/vsmolyakov/experiments_with_python/blob/master/chp01/ensemble_methods.ipynb,

进行代码检测,报错了使用Python3.x版本。

plt.figure() (_, caps, _) = plt.errorbar(num_est, bg_clf_cv_mean, yerr=bg_clf_cv_std, c='blue', fmt='-o', capsize=5) for cap in caps:cap.set_markeredgewidth(1) plt.ylabel('Accuracy'); plt.xlabel('Ensemble Size'); plt.title('Bagging Tree Ensemble'); plt.show()

实际上在这个例子中,有一行num_est = map(int, np.linspace(1,100,20)),这个在Python的2.7版本中产生的是一个List,而在Python3.x中产生的是一个Generators,所有建议把这一个替换成:

num_est = np.linspace(1,100,20).astype(int)

 

总结

以上是生活随笔为你收集整理的Python总结:RuntimeError: matplotlib does not support generators as input的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。