290-9 Numpy boolean indexing Unable to understand!

Can anyone explain boolean indexing with numpy page 9!
I’m unable to understand!

1 Like

Hi @rahulpathak could you please articulate what is it that you do not understand?
I’m pasting before my solution with pseudocode in it - I think it could be of help in understanding what the interpreter is doing.

So in the first instance:

  1. taxi[:,6] == 2 --> This acts as the boolean array: it will return an array of true / false values, where the condition to assess whether a value is true or false is to check if the row value (that is, the dropoff_location_code) is equal to 2.

  2. use that array as a filter to taxi to return an ndarray with the chosen condition --> taxi[taxi[:,6] == 2]

  3. retrieve the count of values with the .shape[0] attribute

Let me know if it makes any sense!
Cheers,
nlong

1 Like