当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python tensorflow.math.reduce_logsumexp()用法及代码示例


TensorFlow是Google设计的开源Python库,用于开发机器学习模型和深度学习神经网络。

reduce_logsumexp()用于计算张量维度上元素的对数和exp。

用法:tensorflow.math.reduce_logsumexp( input_tensor, axis, keepdims, name)

参数:

  • input_tensor:是减少的数字张量。
  • axis(optional):它表示要缩小的尺寸。其值应在[-rank(input_tensor),rank(input_tensor))范围内。如果对此没有给出值,则所有尺寸都会减小。
  • keepdims(optional):默认值为False。如果将其设置为True,它将保留长度为1的缩小尺寸。
  • name(optional):它定义了操作的名称。

返回值:它返回一个张量。



范例1:

Python3

# importing the library 
import tensorflow as tf 
  
# Initializing the input tensor 
a = tf.constant([1, 2, 3, 4], dtype = tf.float64) 
  
# Printing the input tensor 
print('Input:', a) 
  
# Calculating result 
res = tf.math.reduce_logsumexp(a) 
  
# Printing the result 
print('Result:', res)

输出:

Input: tf.Tensor([1. 2. 3. 4.], shape=(4, ), dtype=float64)
Result: tf.Tensor(4.440189698561196, shape=(), dtype=float64)



范例2:

Python3

# importing the library 
import tensorflow as tf 
  
# Initializing the input tensor 
a = tf.constant([[1, 2], [3, 4]], dtype = tf.float64) 
  
# Printing the input tensor 
print('Input:', a) 
  
# Calculating result 
res = tf.math.reduce_logsumexp(a, axis = 1, keepdims = True) 
  
# Printing the result 
print('Result:', res)

输出:

Input: tf.Tensor(
[[1. 2.]
 [3. 4.]], shape=(2, 2), dtype=float64)
Result: tf.Tensor(
[[2.31326169]
 [4.31326169]], shape=(2, 1), dtype=float64)



相关用法


注:本文由纯净天空筛选整理自aman neekhara大神的英文原创作品 Python – tensorflow.math.reduce_logsumexp()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。