def make_frac(a, denom):
 a = (np.array(a, dtype=float) / sum(a))
 b = [float((v * denom)) for v in a]
 b = np.array(b, dtype=int)
 err = ((b / float(denom)) - a)
 inds = np.argsort(err)[:(denom - sum(b))]
 b[inds] += 1
 denom = int(denom)
 b = b.tolist()
 return tuple((Fraction(v, denom) for v in b))

def make_frac ( a , denom ) : a = ( np . array ( a , dtype = float ) / sum ( a ) ) b = [ float ( ( v * denom ) ) for v in a ] b = np . array ( b , dtype = int ) err = ( ( b / float ( denom ) ) - a ) inds = np . argsort ( err ) [ : ( denom - sum ( b ) ) ] b [ inds ] += 1 denom = int ( denom ) b = b . tolist ( ) return tuple ( ( Fraction ( v , denom ) for v in b ) )
approximate a/sum(a) with tuple of fractions with denominator *exactly* denom .