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

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) 

新增連結描述