I have an array representing a video. Currently the way it is set up is the first element is an array of all the values of the first pixel at all the different time steps, then the second element is of the second pixel and so on. I want it so the first element would be an array of all the pixels at the first time step.
So for two frames of a 2x2 video, I would want
[
[
[a1, a2, a3], [b1, b2, b3]
],
[
[c1, c2, c3], [d1, d2, d3]
]
]
to become
[
[
[a1, b1],
[c1, d1]
],
[
[a2, b2],
[c2, d2]
],
[
[a3, b3],
[c3, d3]
],
]
My current implementation is this:
def remap_image(seq):
# seq = np.array(seq)
s = seq.shape
a = np.zeros((s[2], s[0], s[1]))
for x, px in enumerate(tqdm(seq)):
for y, py in enumerate(px):
for p_counter, value in enumerate(py):
a[p_counter][x][y] = value/100.
return a
This works as intended however this approach is incredibly slow. Is there any faster way to do this?
seq.transpose(2, 0, 1)