scipy.special.entr#
- scipy.special.entr(x, out=None) = <ufunc 'entr'>#
用於計算熵的逐元素函數。
\[\begin{split}\text{entr}(x) = \begin{cases} - x \log(x) & x > 0 \\ 0 & x = 0 \\ -\infty & \text{otherwise} \end{cases}\end{split}\]- 參數:
- xndarray
輸入陣列。
- outndarray, optional
函數值的選用性輸出陣列
- 回傳值:
- res純量或 ndarray
在給定點 x 的逐元素熵函數值。
另請參閱
註解
在 0.15.0 版本中新增。
此函數為凹函數。
此函數的起源在於凸優化;請參閱 [1]。給定一個機率分佈 \(p_1, \ldots, p_n\),在資訊理論的上下文中,熵的定義為
\[\sum_{i = 1}^n \mathrm{entr}(p_i).\]若要計算後者,請使用
scipy.stats.entropy
。參考文獻
[1]Boyd, Stephen and Lieven Vandenberghe. Convex optimization. Cambridge University Press, 2004. DOI:https://doi.org/10.1017/CBO9780511804441