Python – tensorflow.constant_initializer()
TensorFlow是谷歌设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
constant_initializer()是初始化器,用于生成具有常量值的Tensor。
语法: tensorflow.constant_initializer( value )
参数:
- value :它是需要被转换为Tensor的值。它可以是Python标量、列表或元组的值,或者是N维的Numpy数组。
返回:它返回一个初始化器实例。
例子1:来自Python列表
# Importing the library
import tensorflow as tf
# Initializing the input
l = [1, 2, 3, 4]
# Printing the input
print('l: ', l)
# Calculating result
x = tf.constant_initializer(l)
# Printing the result
print('x: ', x)
输出:
l: [1, 2, 3, 4]
x: tensorflow.python.ops.init_ops_v2.Constant object at 0x7fa7f2e1ab00
例子2:来自Python元组
# Importing the library
import tensorflow as tf
# Initializing the input
l = (1, 2, 3, 4)
# Printing the input
print('l: ', l)
# Calculating result
x = tf.constant_initializer(l )
# Printing the result
print('x: ', x)
输出:
l: (1, 2, 3, 4)
x: tensorflow.python.ops.init_ops_v2.Constant object at 0x7fa7f2e1ab00