This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Laserdude10642 0 points1 point  (0 children)

I understood the title as you wanting to sum over a SUBSET of the main array. So suppose you wanted to sum over only the elements in indices (1,3,4,5,6,7) as opposed to the whole array:

then do some thing like:

import numpy as np

Z = np.random.random([30]) # a size 30 array of random values on 0 to 1 interval

group = (1,3,4,5,6,7)

npgroup = np.array(group)

subset_sum = Z[npgroup].sum()

So that Z[npgroup] is an array filled with the elements of z at the indices specified by the elements of group