Dinosaurus model - W1-A2 Exercise 4 - model- Wrong output

I am getting the wrong output. Can someone guide me on what is wrong? my loss calculation is wrong but the previous step was correct

Please click my name and message your notebook as an attachment.

idx = (j + 1) % (j + 1) is incorrect.
This is always going to be 0 .
What you want is this:
if j \in [0, len(examples) - 1], idx = j
if not, map j to this range and before assigning idx.

As provided in the assignment writeup, use the % operator for this.