Screen Link: https://app.dataquest.io/m/290/boolean-indexing-with-numpy/8/assignment-using-boolean-arrays-continued
Guys I used two different ways of creating a boolean array to perform assignment operation
The first method runs and code is successful, the second method runs but the o/p prompt tells that output is incorrect. I want to know if my logic for the second one is incorrect or not?
Code for the both is given below, (Please let me know, Thank you!):
Code for first one (which is successful) :
# create a new column filled with `0`.
zeros = np.zeros([taxi.shape[0], 1])
taxi_modified = np.concatenate([taxi, zeros], axis=1)
print(taxi_modified)
pickup = taxi_modified[:,5]
condition = pickup == 2
taxi_modified[condition, 15] = 1
print(taxi_modified)
pickup = taxi_modified[:,5]
condition = pickup == 3
taxi_modified[condition, 15] = 1
pickup = taxi_modified[:,5]
condition = pickup == 5
taxi_modified[condition, 15] = 1
Code for the second type:
# create a new column filled with `0`.
zeros = np.zeros([taxi.shape[0], 1])
taxi_modified = np.concatenate([taxi, zeros], axis=1)
print(taxi_modified)
pickup = taxi_modified[:,5]
condition = (pickup == (2 or 3 or 5))
taxi_modified[condition, 15] = 1
print(taxi_modified)