other_indices in the last cell is an array of boolean, shouldn’t it be integers?
other_indices = [cur_idx != target_indices for cur_idx, _ in enumerate(feature_names)]
should be
other_indices = [cur_idx for cur_idx, _ in enumerate(feature_names) if cur_idx != target_indices]
I think either implementation should work. The first is just an instance of what they call “logical indexing” in MATLAB. I don’t know python terminology well enough to know if they have their own name for this type of operation, but it’s analogous to implementing ReLU by saying
Z[Z < 0] = 0
As we see in that case, being able to index an array with an array of Booleans is a powerful idea that lets us write compact and expressive code. You could also implement that using your style of coding, but try it and I hope you’ll agree the above is cleaner and clearer.
But please let me know if I’m just missing your point here. 
1 Like