1

I am trying to add an array of (174, 2, 2) to itself vertically. So far I am able to do it in non-numpy way:

import numpy as np
cm1 = np.random.rand(174, 2, 2)
temp_array = np.zeros([2, 2])

for _content in cm1:
    temp_array = np.add(temp_array, _content)

print(temp_array)

I am able to get the results, but is there a numpy way of doing this?

1 Answer 1

1

You can use sum with parameter axis=0 as:

cm1.sum(axis=0)
array([[82.39817762, 84.41947252],
       [91.82740901, 83.53547764]])
Sign up to request clarification or add additional context in comments.

1 Comment

Ah yes. Thanks for that.

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.