C2_W4_Decision_Tree_with_Markdown is there cleaner way to get left/right indices?

Is there some declarative way with numpy arrays to get left_indices/right_indices? Looping works but feels like there should be way to just filter the matrix directly.

for i in node_indices:
    if X[i][feature] == 1:

You could try using np.where() twice instead of a for-loop.

1 Like

Would have loved to see some examples after the assignment showing optimized methods for doing the task. I enjoy the challenge of building my own stuff but would also like to see “Here’s how you should have done it” after it’s done. Though I guess yay, more future self led projects.

With this sort of online course, it’s very difficult to manage the impact of publishing a reference solution without making it way too easy to pass the course without learning anything.

Hello @Gabriel_Paiz,

You may also want to check np.argwhere out.