def is_weight(w):
 if isinstance(w, np.ndarray):
  w = w.tolist()
 valid_elems = all((((v >= 0) and isinstance(v, (numbers.Integral, Fraction))) for v in w))
 return (valid_elems and (sum(w) == 1))

def is_weight ( w ) : if isinstance ( w , np . ndarray ) : w = w . tolist ( ) valid_elems = all ( ( ( ( v >= 0 ) and isinstance ( v , ( numbers . Integral , Fraction ) ) ) for v in w ) ) return ( valid_elems and ( sum ( w ) == 1 ) )
test if w is a valid weight vector .