I have written the following code in a programming exercise:
q = lenP[0]*[lenP[1]*[0.]] # empty 2D array
for i in range(lenP[0]):
for j in range(lenP[1]):
hit = (Z == colors[i][j])
q[i][j] = (hit * sensor_right + (1-hit) * (1.-sensor_right)) * p[i][j]
The value of every element q[i][j] is correctly set if I test for it inside the loop. But, if I print any q[i][j] outside of the loop, it has reverted to its initial value of 0. I think I have missed something in the management of python references to object, but what would that be ?
In a normal setting I would have used numpy for the array and be done with it, but this is a code for an Udacity course (IA for Robotics, very interesting by the way) and one is not allowed to import anything.