TensorFlow是Google設計的開源Python庫,用於開發機器學習模型和深度學習神經網絡。
cumulative_logsumexp()用於計算輸入張量的累積log-sum-exp。此操作等效於tensorflow.math.log(tensorflow.math.cumsum(tensorflow.math.exp(x))),但在數值上更穩定。
用法:tensorflow.math.cumulative_logsumexp( x, axis, exclusive, reverse, name)
參數:
- x:它是輸入張量。該張量的允許dtype為float16,float32,float64。
- axis(optional):這是int32類型的張量。該值應在int32類型的Tensor範圍內(默認值:0)。必須在[-rank(x),rank(x))範圍內。預設值為0。
- exclusive(optional):它是布爾型的。默認值為False。
- reverse(optional):它是布爾型的。默認值為False。
- name(optional):它定義了操作的名稱。
返回值:
它返回與x相同dtype的張量。
範例1:
Python3
# imporing the library
import tensorflow as tf
# initializing the input
a = tf.constant([1, 2, 4, 5], dtype = tf.float64)
# Printing the input
print("Input:",a)
# Cumulative log-sum-exp
res = tf.math.cumulative_logsumexp(a)
# Printing the result
print("Output:",res)
輸出:
Input: tf.Tensor([1. 2. 4. 5.], shape=(4,), dtype=float64) Output: tf.Tensor([1. 2.31326169 4.16984602 5.36184904], shape=(4,), dtype=float64)
範例2:在此示例中,reverse和Exclusive都設置為True。
Python3
# imporing the library
import tensorflow as tf
# initializing the input
a = tf.constant([2, 3, 4, 5], dtype = tf.float64)
# Printing the input
print("Input:",a)
# Cumulative log-sum-exp
res = tf.math.cumulative_logsumexp(a, reverse = True, exclusive = True)
# Printing the result
print("Output:",res)
輸出:
Input: tf.Tensor([2. 3. 4. 5.], shape=(4,), dtype=float64) Output: tf.Tensor([ 5.40760596e+000 5.31326169e+000 5.00000000e+000 -1.79769313e+308], shape=(4,), dtype=float64)
相關用法
注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python – tensorflow.math.cumulative_logsumexp()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。