def sum_1st(data):
    y = np.zeros(data.shape[1:], data.dtype)
it = np.nditer(y, flags=['multi_index'])
while not it.finished:
    xindex = tuple([slice(None)] + list(it.multi_index))
y[it.multi_index] = data[xindex].sum()
it.iternext()
return y
How to do a reduction with numpy.nditer in the first axis