简体   繁体   English

在 Python 中将第 3 维添加到 2D 数组

[英]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.

相关问题 python:追加 2D 和 3D 数组以生成新的 3D(更大的第 3 维) - python: Appending 2D and 3D array to make new 3D (bigger 3rd dimension) 如何将二维数组复制到第三维,N 次? - How to copy a 2D array into a 3rd dimension, N times? 如何从Python numpy 3D数组转换为2D再转换为1D再转换为2D(保留3D数组的原始第2维和第3维) - How to go from Python numpy 3D array to 2D to 1D back to 2D (preserving the original 2nd and 3rd dimension of the 3D array) Python:基于具有第三维索引的相应数组将2D阵列拉伸成3D - Python: Stretch 2D array into 3D based on corresponding array with 3rd-dimension index 沿第三维在 Python 中取百分位数 - Taking percentile in Python along 3rd dimension Python:第3维的Numpy Tile - Python: Numpy tile in the 3rd dimension 如何在 3D numpy 数组的第 3 维中转换列表对象类型? - How to convert list object type in 3rd dimension of 3D numpy array? 图像数组的维度是 3D 而不是 Python 课程中的二维 - The dimension of the array of an image is 3D not 2D as it is in the Python course Python将2个字典连接到第3个2D字典中,其中字典2的键是字典1中的列表值 - Python Join 2 dictionaries into 3rd, 2D dictionary where key from dictionary 2 is list value in dictionary 1 如何在 python 3 中以颜色密度作为第三个参数制作二维图 - How to make a 2D plot with color density as the 3rd argument in python 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM