N = 100 # number of points per class
D = 2 # dimensionality
K = 3 # number of classes
X = np.zeros((N*K,D))
y = np.zeros(N*K, dtype='uint8')
for j in xrange(K):
ix = range(N*j,N*(j+1))
r = np.linspace(0.0,1,N) # radius
t = np.linspace(j*4,(j+1)*4,N) + np.random.randn(N)*0.2 # theta
X[ix] = np.c_[r*np.sin(t), r*np.cos(t)]
y[ix] = j
fig = plt.figure()
plt.scatter(X[:, 0], X[:, 1], c=y, s=40, cmap=plt.cm.Spectral)
plt.xlim([-1,1])
plt.ylim([-1,1])
plt.show()
这是代码,它来自这里:https://cs.stanford.edu/people/karpathy/cs231nfiles/minimal_net.html
这里我唯一不理解的是这一行:
plt.scatter(X[:, 0], X[:, 1], c=y, s=40, cmap=plt.cm.Spectral)
我们如何对列表进行(X:,0)操作,以及这个操作是做什么的?
发布于 2018-06-25 04:29:33
X不是内置python列表。它是一个数值数组。请查看zeros
https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.zeros.html的文档
和索引数组:https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html
https://stackoverflow.com/questions/51013667
复制相似问题