> for h in 0..H: > > for w in 0..W: This is the source of your error — you're trying to do something at positions `H` and `W`, and your array has `H` elements: from `0` to `H-1`.
To fix it, use `..<` which excludes upper limit:
for h in 0 ..< H:
for w in 0 ..< W:
Run
