What causes the error code ( broadcasting error)?

I got this error code when I wrote a first solution to the split_dataset(). I am not entirely sure what causes it.


I used this to try to iterate through all rows, I thought that was how it had been done earlier in the course.

Now I’ve fixed my code and everything works. But it like to know what’s happening here! :slight_smile:

This must be a simple error. I think you know your error, since you seemed to fix it.

" X.shape[0]", the number of samples, is equal or larger than “node_indices” which is the list of “active indices”. But, your old code always check all samples. In the error case, there are 11 samples in X. But, node_indices has only 7. As the result, you put 11 samples to either left or right. But, expected result is to put 7 samples to either left or right. Since the array size is different, a broadcasting error should be shown up.

Hope this clarifies.

Screenshot from 2022-08-02 22-28-12

I was about to write a reply, but @anon57530071 has given us a very good direction, so I would just to post the description of the exercise here which tells us which index we need to iterate through.

Good luck @Rickard


thank you! Yeah I realised that I hadn’t read the instructions thoroughly enough… Now I get it!

1 Like