Maybe I’m misunderstanding the requirements because I think I’m doing what’s asked but not passing the unit tests.
We’re taking 2 inputs:
y = a np.array of zeroes with a shape of (1,1375) representing the audio steps
segment_end_ms = which is the end of the positive segment in ms
The given code converts segment_end_ms to segment_end_y which is the step in y which the segment ends.
We’re asked to start at the step = segment_end_y+1 and set all the successive values of y to 1. So if segment_end_y = 30 the values of y[0,31:1374] should be set to 1. Is that correct?
I got the tests to pass by implementing the segment_end_y+51 you mentioned but in the sanity check cell 48 I got this error:
<ipython-input-48-21e1908c08b9> in <module>
----> 1 arr1 = insert_ones(np.zeros((1, Ty)), 9700)
<ipython-input-46-7eb81572289d> in insert_ones(y, segment_end_ms)
26 for i in range(segment_end_y, segment_end_y+51):
27 if segment_end_y < i:
---> 28 y[0, i] = 1
29 ### END CODE HERE ###
30
IndexError: index 1375 is out of bounds for axis 1 with size 1375
Is there something wrong with my if statement? Did you figure out a better way?
Another addition to the above “hacky” solution to the problem , i added another condition in the if statement to pass the “sanity check” ! if i < 1375 and segment_end_y < i:)
Why is that “hacky” if the instructions are to set 50 values to 1? Well, it might be a little more elegant if they had made the number of 1 values to set be a parameter. But the instructions are pretty clear as written.