What's that slicing doing here-
data = np.loadtxt(input_file, delimiter=',')
X, y = data[:, :-1], data[:, -1]
I know that -1 inverts the list and colon is start and stop signals.But what's the comma (,)
doing in the middle?
What's that slicing doing here-
data = np.loadtxt(input_file, delimiter=',')
X, y = data[:, :-1], data[:, -1]
I know that -1 inverts the list and colon is start and stop signals.But what's the comma (,)
doing in the middle?
NumPy supports multiple dimensions. In your case that's a 2D slice: the part before the comma slices the first dimension, and after the comma slices the second dimension. This implies the data is 2D or greater, and indeed loadtxt()
does produce 2D arrays.
Ref: https://docs.scipy.org/doc/numpy-1.13.0/reference/arrays.indexing.html