Hi

I have this code and a problem that i don't understand. In image_matrix, a PixelArray object where there is a image. I want to separate this image in frames then I capture pixel by pixel in a double for with the dimensions of frame. The variable h represents each image. self.TileSnc is a list. Each position of this list represent an image that I read and contains another list with each frame of image. The problem is:
Every time that the for h in range(int(max_pos)) executes the line self.TileSnc[stat][pos] = image_sonic would be put the frame (image_sonic) in the position pos, but every positions in self.TileSnc[stat] received the same frame. Can someone say me what's wrong with my code. Thank you very much.

``````for h in range(int(max_pos)):
pos = pos + 1
for i in range(int(height)):
for j in range(int(frame)):
image_sonic[j][i] = image_matrix[frame*(pos-1)+j][i]

self.TileSnc[stat][pos] = image_sonic``````
2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by lumeniel

I think the problem is that you always use the same `image_sonic` . For example, each time you go through the double `for i ... for j ...` , the value of `image_sonic[0][0]` is modified, but since all `self.TileSnc[stat][pos]` are this same `image_sonic` object (or array), evrey loop erases the previous one.
What you should do is to define a new `image_sonic` object at each loop like this

``````for h in ...:
image_sonic = create_frame(int(height), int(frame))
...
for i ...
for j ...``````

And create frame is a function returning a new object, like this one if your objects are just arrays

``````def create_frame(height, width):
L = []
for i in range(height):
L.append([None] * width)
return L``````

But may be your array are Numerical python arrays or something else, so write your own create_frame :)

You really help me.

Thank you so much