1

I have the following numpy array dimension: [64, 897]. This data is generated after each experiment. I have 8 subjects in total and I did the experiments 6 times per subject.

Therefore, I would like to have at the end a 4 dimensional array of the following size: [8, 6, 64, 897].

How can I achieve this in numpy in python.

Any help is much appreciated!!

1
  • Take a look at np.stack specifying axis=0 Commented Sep 8, 2019 at 22:58

1 Answer 1

1

According to @rafaelc, here is the solution:

total_slices = []

for i in range(8):
    slices_ = []
    for j in range(6):
        slices = result_of_experiment()   # This will return an np.array of shape: [64, 8970
        slices_.append(slices)

    slices = np.stack(slices_, axis=0)
    print("slices.shape", slices.shape)
    total_slices.append(slices)

total_slices = np.stack(total_slices, axis=0)
print("total_slices.shape", total_slices.shape)
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.