In the assignment of DLS 1 week 3:
X is a (2,400) array, it looks X[0] and X[0,:] are the same and the diagram made by the following two lines of code are the same too.
plt.scatter(X[0,:], X[1,:], c=Y, s=40, cmap=plt.cm.Spectral);
plt.scatter(X[0], X[1], c=Y, s=40, cmap=plt.cm.Spectral);
So why use X[0,:] instead of X[0]? Does X[0,:] make any differences?
Difference between X[0] and X[0, :] depends on the dimensionality of the array X.
1-Dimensional Array
If X is a 1-dimensional array, X[0] returns the element at the first index.
X[0, :] would result in an error because you are trying to use slicing ( : ) along the second axis, which doesn’t exist in a 1-dimensional array.
2-Dimensional Array
If X is a 2-dimensional array, both X[0] and X[0, :] will return the first row of the array.
The other subtlety here would be to make sure that the “shape” of the output is the same. Here’s a little experiment that shows that it is. Notice that the output is a 1D array in both cases. You start with a 2D array and you “slice” it on one dimension.