Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

我在运行的时候一直遇到问题 #7

Open
bois93 opened this issue Feb 28, 2018 · 1 comment
Open

我在运行的时候一直遇到问题 #7

bois93 opened this issue Feb 28, 2018 · 1 comment

Comments

@bois93
Copy link

bois93 commented Feb 28, 2018

你好,我在运行的时候一直遇到这样的问题
比如第二课,第一周的Regularization
train_X, train_Y, test_X, test_Y = load_2D_dataset()
哎困扰我很久了,一直没有找到原因

TypeError Traceback (most recent call last)
c:\users\administrator\appdata\local\programs\python\python36-32\lib\site-packages\matplotlib\colors.py in to_rgba(c, alpha)
131 try:
--> 132 rgba = _colors_full_map.cache[c, alpha]
133 except (KeyError, TypeError): # Not in cache, or unhashable.

TypeError: unhashable type: 'numpy.ndarray'

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
c:\users\administrator\appdata\local\programs\python\python36-32\lib\site-packages\matplotlib\axes_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
3985 # must be acceptable as PathCollection facecolors
-> 3986 colors = mcolors.to_rgba_array(c)
3987 except ValueError:

c:\users\administrator\appdata\local\programs\python\python36-32\lib\site-packages\matplotlib\colors.py in to_rgba_array(c, alpha)
232 for i, cc in enumerate(c):
--> 233 result[i] = to_rgba(cc, alpha)
234 return result

c:\users\administrator\appdata\local\programs\python\python36-32\lib\site-packages\matplotlib\colors.py in to_rgba(c, alpha)
133 except (KeyError, TypeError): # Not in cache, or unhashable.
--> 134 rgba = _to_rgba_no_colorcycle(c, alpha)
135 try:

c:\users\administrator\appdata\local\programs\python\python36-32\lib\site-packages\matplotlib\colors.py in _to_rgba_no_colorcycle(c, alpha)
188 if len(c) not in [3, 4]:
--> 189 raise ValueError("RGBA sequence should have length 3 or 4")
190 if len(c) == 3 and alpha is None:

ValueError: RGBA sequence should have length 3 or 4

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)
in ()
----> 1 train_X, train_Y, test_X, test_Y = load_2D_dataset()

~\Desktop\deeplearning.ai_JupyterNotebooks-master\deeplearning.ai_JupyterNotebooks-master\2_Improving Deep Neural Networks Hyperparameter tuning, Regularization and Optimization\week1\2_Regularization\reg_utils.py in load_2D_dataset()
332 test_Y = data['yval'].T
333
--> 334 plt.scatter(train_X[0, :], train_X[1, :], c=train_Y, s=40, cmap=plt.cm.Spectral);
335
336 return train_X, train_Y, test_X, test_Y

c:\users\administrator\appdata\local\programs\python\python36-32\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, hold, data, **kwargs)
3376 vmin=vmin, vmax=vmax, alpha=alpha,
3377 linewidths=linewidths, verts=verts,
-> 3378 edgecolors=edgecolors, data=data, **kwargs)
3379 finally:
3380 ax._hold = washold

c:\users\administrator\appdata\local\programs\python\python36-32\lib\site-packages\matplotlib_init_.py in inner(ax, *args, **kwargs)
1715 warnings.warn(msg % (label_namer, func.name),
1716 RuntimeWarning, stacklevel=2)
-> 1717 return func(ax, *args, **kwargs)
1718 pre_doc = inner.doc
1719 if pre_doc is None:

c:\users\administrator\appdata\local\programs\python\python36-32\lib\site-packages\matplotlib\axes_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
3989 msg = ("c of shape {0} not acceptable as a color sequence "
3990 "for x with size {1}, y with size {2}")
-> 3991 raise ValueError(msg.format(c.shape, x.size, y.size))
3992 else:
3993 colors = None # use cmap, norm after collection is created

ValueError: c of shape (1, 211) not acceptable as a color sequence for x with size 211, y with size 211

@SStar1314
Copy link

SStar1314 commented Mar 30, 2018

@bois93 打开reg_utils.py 文件,修改load_2D_dataset 函数, 把其中一行换成 : plt.scatter(train_X[0, :], train_X[1, :], c=np.squeeze(train_Y), s=40, cmap=plt.cm.Spectral);
重新运行jupyter notebook 就可以了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants