简体   繁体   中英

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. 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). So I want Python to multiplicate the zeros and ones in the 2nd dimension 1800 times into the 3rd dimension.

How can I do that?

with an array called array with any 2D shape:

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.

It also seems to make more sense to have a shape (4432, 1800, 35): (video, frame, customers in frame):

array = [[i for k in range(1800)] for i in array]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM