abc = np.array(np.arange(2*3*4)).reshape((2,3,4))
abc
print(abc.sum(0))
print(abc.sum(1))
print(abc.sum(2))
print(abc.sum(0).sum(0))
print(abc.sum(0).sum(1))
print(abc.sum(1).sum(0))
print(abc.sum(1).sum(1))
print(abc.sum(2).sum(0))
print(abc.sum(2).sum(1))
def myarray_sum(x,v):
ret = x
for i in range(v.size):
ret = ret.sum(v[i]-i)
return ret
print(myarray_sum(abc,np.array([0])))
print(myarray_sum(abc,np.array([0,1])))
print(myarray_sum(abc,np.array([0,2])))
print(myarray_sum(abc,np.array([1])))
[[12 14 16 18]
[20 22 24 26]
[28 30 32 34]]
[[12 15 18 21]
[48 51 54 57]]
[[ 6 22 38]
[54 70 86]]
[60 66 72 78]
[ 60 92 124]
[60 66 72 78]
[ 66 210]
[ 60 92 124]
[ 66 210]
[[12 14 16 18]
[20 22 24 26]
[28 30 32 34]]
[60 66 72 78]
[ 60 92 124]
[[12 15 18 21]