[英]Adding 3rd dimension to 2D array in Python
I'm having a 2D array of dummy variables (0 and 1) with the shape of (4432, 35) -> 4432 videos including 35 different customers.我有一个虚拟变量(0 和 1)的二维数组,形状为 (4432, 35) -> 4432 个视频,包括 35 个不同的客户。 Since the videos contain of 1800 frames I want to add a third dimension to this array with 1800 time steps (frames) so that it gets the shape (4432, 35, 1800).
由于视频包含 1800 帧,我想用 1800 个时间步长(帧)向该数组添加第三维,以便获得形状(4432、35、1800)。 So I want Python to multiplicate the zeros and ones in the 2nd dimension 1800 times into the 3rd dimension.
所以我希望 Python 将第 2 维中的 0 和 1 乘以 1800 次到第 3 维。
How can I do that?我怎样才能做到这一点?
with an array called array with any 2D shape:使用名为 array 的任何二维形状的数组:
array = [[[j for k in range(1800)] for j in i] for i in array]
This will create a 3rd dimension with 1800 duplicates of the values in the second dimension.这将创建第三个维度,其中包含 1800 个第二个维度中的值的重复项。
It also seems to make more sense to have a shape (4432, 1800, 35): (video, frame, customers in frame):形状 (4432, 1800, 35) 似乎也更有意义:(视频,框架,框架中的客户):
array = [[i for k in range(1800)] for i in array]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.