Meaning of X = X[:, 1] in Python

Something you shoud know

The term you need to search for is slice. x[start:end:step] is the full form, Here we can omit to use a default value: start defaults to 0 , end defaults to the length of the list, and step defaults to 1. And hence x[:] means same as x[0:len(x):1]


x = np.random.rand(3,2)

x
Out[37]: 
array([[ 0.03196827,  0.50048646],
       [ 0.85928802,  0.50081615],
       [ 0.11140678,  0.88828011]])

x = x[:,1]

x
Out[39]: array([ 0.50048646,  0.50081615,  0.88828011])

So what that line did is sliced the array, taking all rows (:) but keeping the second column (1)