0
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()

This was the code and it's from here: https://cs.stanford.edu/people/karpathy/cs231nfiles/minimal_net.html

The only thing I don't understand here is this line:

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

How can we do that (X[:, 0]) with lists and what this operation does?

2
  • 4
    X is NumPy array, not a list. X[:, 0] simply slices the second axis. Try X.shape / X.ndim to check the shape of your array. Commented Jun 24, 2018 at 20:26
  • Oh,thanks. I'll definitely checkout the numpy documentation Commented Jun 24, 2018 at 20:35

1 Answer 1

1

X is not a builtin python list. It's a numpy array. Have a look at the documentation for zeros https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.zeros.html

and indexing arrays: https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.