def dirichlet_expectation(alpha):
 if (len(alpha.shape) == 1):
  result = (psi(alpha) - psi(np.sum(alpha)))
 else:
  result = (psi(alpha) - psi(np.sum(alpha, 1))[:, np.newaxis])
 return result.astype(alpha.dtype)

def dirichlet_expectation ( alpha ) : if ( len ( alpha . shape ) == 1 ) : result = ( psi ( alpha ) - psi ( np . sum ( alpha ) ) ) else : result = ( psi ( alpha ) - psi ( np . sum ( alpha , 1 ) ) [ : , np . newaxis ] ) return result . astype ( alpha . dtype )
for a vector theta~dir .