1

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, i.e., 3dArray is of shape (1,250,2), then (2,250,2) etc.

I tried using:

3dArray = np.dstack((3dArray, new2DArray))
3
  • 2
    It's better to collect all 2d arrays in a list, and then do just one stack or dstack. All those concatenate/stack functions takes a list - use that feature! Commented May 14, 2020 at 3:59
  • Never mind, figured it out, thanks again! Commented May 14, 2020 at 4:17
  • 1
    list append is efficient Commented May 14, 2020 at 4:18

1 Answer 1

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

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.