Week 3 Trigger detection ex3

My code for insert_ones passes all tests, as does all my previous code. However, the next provided code In [51]: (not my code) doesn’t run, giving error:

IndexError Traceback (most recent call last)
----> 1 arr1 = insert_ones(np.zeros((1, Ty)), 9700)
2 plt.plot(insert_ones(arr1, 4251)[0,:])
3 print(“sanity checks:”, arr1[0][1333], arr1[0][634], arr1[0][635])

in insert_ones(y, segment_end_ms)
27 #print(y[-1].shape) #if y[1].shape < i:
28 #print(i)
—> 29 if y[0,i] < 1:
30 y[0,i] = 1
31 ### END CODE HERE ###

IndexError: index 1375 is out of bounds for axis 1 with size 1375

The error message indicates that values assigned to i are bigger than the size of the array y. You may want to look at your for loop’ bounds again.

my for loop range is (segment_end_y+1, segment_end_y+51). No other bounds pass the tests.

segment_end_y may be close to Ty, and (segment_end_y +51) may be over boundary (Ty).


Hi, how have you been able to fix this issue?

I have been stuck on the same problem and am not sure how to fix the indices.

Thank you for any hints!

After spending more time on this I figured out my indices were correct but I made a mistake in the if-statement. All good now and passing the tests!

Could you give any hints on what the mistake was? I am having the same problem