0

I am new to Python and machine learning and I am confused what are these colons in someplace(arrays) they appear and some they don't can someone explain to me what are those?

Don't mind me I am a noob.

companies = pd.read_csv('D:/Programming/Python/TensorFlow/Datasets/Linear Regression/1000_Companies.csv')
X = companies.iloc[:, :-1].values
y = companies.iloc[:, 4].values

#changing the name of cities to machine understandable format
labelencoder = LabelEncoder()
X[:, 3] = labelencoder.fit_transform(X[:, 3])
ct = ColumnTransformer(
    [('one_hot_encoder', OneHotEncoder(), [3])],    # The column numbers to be transformed (here is [0] but can be [0, 1, 3])
    remainder='passthrough'                         # Leave the rest of the columns untouched
)
X = np.array(ct.fit_transform(X), dtype=np.float)
X = X[:, 1:]
Jay Patel
  • 19
  • 5
  • 2
    Does this answer your question? [Understanding slice notation](https://stackoverflow.com/questions/509211/understanding-slice-notation) – Chase Aug 12 '20 at 12:37

2 Answers2

0

The colons are used to index and slice items in a list. For example, [1:] would mean the second element to the last element in a list, and [:] would mean all items in the list.

Gavin Wong
  • 1,152
  • 1
  • 4
  • 13
0

The colon means that you are grabbing everything from that particular dimension. For example, using A[i, :] means you are taking all values from the ith row. A[:, j] means you look at all rows in column j. Even in the third dimension if you say, A[:, :, k], this means that you are taking all rows and columns of page k of the third dimensional array.

Kevin D.
  • 104
  • 8