我尝试在我制作的 tf-gpu 环境中卸载并重新安装 matplotlib,但我不断收到此错误:
ImportError: cannot import name 'rcParams' from 'matplotlib'
Run Code Online (Sandbox Code Playgroud)
这是我在 jupyter 笔记本上得到的完整输出:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-9-8d7d44d0fddd> in <module>
17 # import matplotlib.pyplot as plt
18 from sklearn.metrics import confusion_matrix
---> 19 from mlxtend.plotting import plot_confusion_matrix
20
21 # Removes annoying warning messages in tensorflow and python
~\AppData\Local\Continuum\anaconda3\envs\tf-gpu\lib\site-packages\mlxtend\plotting\__init__.py in <module>
5 # License: BSD 3 clause
6
----> 7 from .decision_regions import plot_decision_regions
8 from .learning_curves import plot_learning_curves
9 from .plot_confusion_matrix import plot_confusion_matrix
~\AppData\Local\Continuum\anaconda3\envs\tf-gpu\lib\site-packages\mlxtend\plotting\decision_regions.py in …Run Code Online (Sandbox Code Playgroud) 给定一些数组 nums 和一个正整数 k,确定是否可以将这个数组分成 k 个连续数字的集合。
例子:
nums = [1,2,3,4] k = 2
Run Code Online (Sandbox Code Playgroud)
从 [1,2], [3, 4] 开始输出真
我的想法是数组 nums 的大小必须能被整数 k 整除。但是当我使用它作为测试时,我在这个测试用例中失败了:
[15,16,17,18,19,16,17,18,19,20,6,7,8,9,10,3,4,5,6,20] k = 5
我是真的,但答案是假的,我不知道为什么。有任何想法吗?
这是我的代码:
int n = nums.size();
if(n % k == 0)
return true;
return false;
Run Code Online (Sandbox Code Playgroud)
如果有帮助,这里有更多示例: