def unbroadcast_numpy_to ( array , shape ) : axis = create_unbroadcast_axis ( shape , numpy . shape ( array ) ) return numpy . reshape ( numpy . sum ( array , axis = axis ) , shape )
python reshape to broadcast sum
Reverse the broadcasting operation .
def unbroadcast_numpy_to(array, shape):
  """Reverse the broadcasting operation.

  Args:
    array: An array.
    shape: A shape that could have been broadcasted to the shape of array.

  Returns:
    Array with dimensions summed to match `shape`.
  """
  axis = create_unbroadcast_axis(shape, numpy.shape(array))
  return numpy.reshape(numpy.sum(array, axis=axis), shape)