2

I am trying to sum the values of a nD array along a particular axis to effectively collapse it into a 1D array. I have been looking through the docs but haven't been able to find the right function. I will try to explain my question better with some code:

In [46]: g
Out[46]: 
array([[1, 2, 3],
       [1, 2, 3],
       [1, 2, 3],
       [1, 2, 3],
       [1, 2, 3]])

The output I need is:

array([5,10,15])

My actual data is a 7 MB file so I don't really want to use a for loop.

Thank you for your help

1 Answer 1

6

Just doing

numpy.sum(g, axis=0)

should work.

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

1 Comment

aaah, I was looking at ma.compress and things.. way off. Thanks!

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.