0

The title basically explains it, I'm new to arrays and I need to add the columns, here is my array:

[[20,40,60,21,70]
[2,76,5,90,50]
[21,67,99,33,49]]

So I need to add (20 + 2 + 21), (40 + 76 + 67) etc..

I tried using np.sum but I'm somewhat new to arrays so I'm not sure how to slice/ index properly with arrays.

Thank you for your help

0

1 Answer 1

2

Use axis=0 in the sum function:

a = np.arange(15).reshape(-1,5)
# array([[ 0,  1,  2,  3,  4],
#   [ 5,  6,  7,  8,  9],
#   [10, 11, 12, 13, 14]])
np.sum(a, axis=0)
# array([15, 18, 21, 24, 27])
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.