def margins(a):
 margsums = []
 ranged = list(range(a.ndim))
 for k in ranged:
  marg = np.apply_over_axes(np.sum, a, [j for j in ranged if (j != k)])
  margsums.append(marg)
 return margsums

def margins ( a ) : margsums = [ ] ranged = list ( range ( a . ndim ) ) for k in ranged : marg = np . apply_over_axes ( np . sum , a , [ j for j in ranged if ( j != k ) ] ) margsums . append ( marg ) return margsums
return a list of the marginal sums of the array a .