def shannonentropy(px, logbase=2):
 px = np.asarray(px)
 if ((not np.all((px <= 1))) or (not np.all((px >= 0)))):
  raise ValueError('px does not define proper distribution')
 entropy = (- np.sum(np.nan_to_num((px * np.log2(px)))))
 if (logbase != 2):
  return (logbasechange(2, logbase) * entropy)
 else:
  return entropy

def shannonentropy ( px , logbase = 2 ) : px = np . asarray ( px ) if ( ( not np . all ( ( px <= 1 ) ) ) or ( not np . all ( ( px >= 0 ) ) ) ) : raise ValueError ( 'px does not define proper distribution' ) entropy = ( - np . sum ( np . nan_to_num ( ( px * np . log2 ( px ) ) ) ) ) if ( logbase != 2 ) : return ( logbasechange ( 2 , logbase ) * entropy ) else : return entropy
this is shannons entropy parameters logbase .