简体   繁体   中英

stack a 2d array into an existing 3d array in numpy

I start by initializing:

3dArray = np.zeros(shape=(0,250,2))

Within a loop, I go through a file and pick out sections of data, resulting in multiple 2D arrays of size (250,2).

For each of these sections, I'm trying to stack these 2d arrays into the 3d array, so that the 0th dimension increases by 1 every time, ie, 3dArray is of shape (1,250,2), then (2,250,2) etc.

I tried using:

3dArray = np.dstack((3dArray, new2DArray))
3DArray = np.vstack((3DArray,new2Darray.reshape(1,250,2)))

Side Note: Python doesn't allow variable names to start with numbers.

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