How can I get the right values for Exercise 2 but get this strange error as well?

Here’s the output when running the test:

Left indices: [0, 1, 2, 3, 4, 7, 9] Right indices: [5, 6, 8]

ValueError Traceback (most recent call last)
in
11
12 # UNIT TESTS
—> 13 split_dataset_test(split_dataset)

~/work/public_tests.py in split_dataset_test(target)
70 ‘right’: np.array([2, 7, 9, 10])}
71
—> 72 assert np.allclose(right, expected[‘right’]) and np.allclose(left, expected[‘left’]), f"Wrong value when target is at index 0. \nExpected: {expected} \ngot: {left:{left}, ‘right’: {right}}"
73
74

<array_function internals> in allclose(*args, **kwargs)

/opt/conda/lib/python3.7/site-packages/numpy/core/numeric.py in allclose(a, b, rtol, atol, equal_nan)
2247
2248 “”"
→ 2249 res = all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan))
2250 return bool(res)
2251

<array_function internals> in isclose(*args, **kwargs)

/opt/conda/lib/python3.7/site-packages/numpy/core/numeric.py in isclose(a, b, rtol, atol, equal_nan)
2356 yfin = isfinite(y)
2357 if all(xfin) and all(yfin):
→ 2358 return within_tol(x, y, atol, rtol)
2359 else:
2360 finite = xfin & yfin

/opt/conda/lib/python3.7/site-packages/numpy/core/numeric.py in within_tol(x, y, atol, rtol)
2337 def within_tol(x, y, atol, rtol):
2338 with errstate(invalid=‘ignore’):
→ 2339 return less_equal(abs(x-y), atol + rtol * abs(y))
2340
2341 x = asanyarray(a)

ValueError: operands could not be broadcast together with shapes (3,) (4,)

1 Like

Hi, I am also getting this exact same error.
Best John.

Hi Raymond,

Here is the code:

Hi John, we don’t encourage learners to share their assignment publicly. Please share it via Direct Message next time, by clicking the receiver’s profile, and click Message.

As for your code, the problem is you are not appending the `node_indices` in your resulting `left_indices` and `right_indices`.

Here is the hint, when the input argument `node_indices` only contains some of the node indices such as `[1,3,5]`, and in your current implementation, you won’t see `5` in either `left_indices` or `right_indices` which is not right.

Hi Raymond,

Sorry I about sharing the code. I thought I had shared directly with you but clearly made an error.

Thanks for the help.

Cheers John.

You are welcome John!