Exercise 2 - random_mini_batches, Course2, week2

Hi all,
I encountered a problem in this assignment. I think I am


wrong somewhere in indexing. Would you please check the attached picture and give me some hints to resolve the errors?

{moderator edit - solution code removed}

The thing to remember is that all indexing in python is “0-based”. That means that if I specify the range 0:4, then that contains 0, 1, 2 and 3. You can try it and see:

v = np.array(range(8))
print(f"v = {v}")
print(v[0:4])
v = [0 1 2 3 4 5 6 7]
[0 1 2 3]

The same thing is true with for loops. Watch what happens:

for ii in range(5):
    print(f"ii = {ii}")

print(f"after loop ii = {ii}")

Running that gives this output:

ii = 0
ii = 1
ii = 2
ii = 3
ii = 4
after loop ii = 4

Perfect! I found the issue and resolved it.
Many thanks :slight_smile: