My Code
new_column = taxi_modified[:,15]
new_column[taxi_modified[:,5] == 2] = 1
new_column[taxi_modified[:,5] == 3] = 1
new_column[taxi_modified[:,5] == 5] = 1
Answer Code
taxi_modified[taxi_modified[:, 5] == 2, 15] = 1
taxi_modified[taxi_modified[:, 5] == 3, 15] = 1
taxi_modified[taxi_modified[:, 5] == 5, 15] = 1
My answer is based on what I have learnt in the fundamentals and intermediate course, which first assigns the column and then use the ‘comparision function’ (Single Dimension)
My question is why is the ‘comparision function’ in the answer located in the ‘row indexing’??? It does not make logical sense as the comparsion should be done outside the indexing?
(Eg: taxi_modified[taxi_modified[: , 15] == 5] = 1)