Meaning of X = X[:, 1] in Python
问题 I am studying this snippet of python code. What does X = X[:, 1] mean in last line? def linreg(X,Y): # Running the linear regression X = sm.add_constant(X) model = regression.linear_model.OLS(Y, X).fit() a = model.params[0] b = model.params[1] X = X[:, 1] 回答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,