def repeat_sum(u,shape,rep_axes):
"""
Computes sum of a repeated matrix
In effect, this routine computes
code:`np.sum(repeat(u,shape,rep_axes))`. However, it performs
this without having to perform the full repetition.
"""
# Must convert to np.array to perform slicing
shape_vec = np.array(shape,dtype=int)
rep_vec = np.array(rep_axes,dtype=int)
# repeat and sum
urep = repeat_axes(u,shape,rep_axes,rep=False)
usum = np.sum(urep)*np.product(shape_vec[rep_vec])
return usum
评论列表
文章目录