访问量: 10 次浏览
tensorflow.math.reduce_std()TensorFlow 是谷歌设计的开源 Python 库,用于开发机器学习模型和深度学习神经网络。
reduce_std() 用于查找张量中各维度元素的标准偏差。
tensorflow.math.reduce_std(input_tensor, axis, keepdims, name)
input_tensor:要减少的数字张量axis(可选):代表要减少的维度。它的值应该在 [-rank(input_tensor), rank(input_tensor)] 范围内。如果没有给这个值,所有的维度都会被减少keepdims(可选):它的默认值是 False。如果它被设置为 True,它将保留长度为 1 的缩小尺寸name(可选):定义该操作的名称返回一个张量。
# 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_std(a)
# Printing the result
print('Result: ', res)
Input: tf.Tensor([1. 2. 3. 4.], shape=(4, ), dtype=float64)
Result: tf.Tensor(1.118033988749895, shape=(), dtype=float64)
# 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_std(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(
[[0.5]
[0.5]], shape=(2, 1), dtype=float64)