ValueError: 'c' argument has 1 elements, which is not acceptable for use with 'x' with size 400, 'y'

在做吴恩达深度学习课程第一课第三周的课后作业时,运行如下代码:

plt.scatter(X[0, :], X[1, :], c=Y, s=40, cmap=plt.cm.Spectral)

报错:

ValueError: 'c' argument has 1 elements, which is not acceptable for use with 'x' with size 400, 'y' with size 400.

这是plt.scatter函数微小的改版造成的,只需要修改如下:

import operator
from functools import reduce
plt.scatter(X[0, :], X[1, :], c=reduce(operator.add, Y), s=40, cmap=plt.cm.Spectral) 

添加链接描述

你可能感兴趣的:(程序人生)