def dist_sum(D1, D2):
 (X1, W1) = D1
 (X2, W2) = D2
 X = numpy.r_[(X1, X2)]
 W = numpy.r_[(W1, W2)]
 sort_ind = numpy.argsort(X)
 (X, W) = (X[sort_ind], W[sort_ind])
 (unique, uniq_index) = numpy.unique(X, return_index=True)
 spans = numpy.diff(numpy.r_[(uniq_index, len(X))])
 W = [numpy.sum(W[start:(start + span)]) for (start, span) in zip(uniq_index, spans)]
 W = numpy.array(W)
 assert (W.shape[0] == unique.shape[0])
 return (unique, W)

def dist_sum ( D1 , D2 ) : ( X1 , W1 ) = D1 ( X2 , W2 ) = D2 X = numpy . r_ [ ( X1 , X2 ) ] W = numpy . r_ [ ( W1 , W2 ) ] sort_ind = numpy . argsort ( X ) ( X , W ) = ( X [ sort_ind ] , W [ sort_ind ] ) ( unique , uniq_index ) = numpy . unique ( X , return_index = True ) spans = numpy . diff ( numpy . r_ [ ( uniq_index , len ( X ) ) ] ) W = [ numpy . sum ( W [ start : ( start + span ) ] ) for ( start , span ) in zip ( uniq_index , spans ) ] W = numpy . array ( W ) assert ( W . shape [ 0 ] == unique . shape [ 0 ] ) return ( unique , W )
a sum of two continuous distributions .