Python – tensorflow.constant_initializer()
TensorFlow 是由 Google 设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
constant_initializer()是生成具有常量值的张量的初始化程序。
Syntax: tensorflow.constant_initializer( value )
Parameters:
- value: It is the value that needed to be converted to Tensor. It can be Python scalar, list or tuple of values, or a N-dimensional numpy array
Returns: It returns an Initializer instance.
示例 1:来自Python列表
Python3
# 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)
Python3
# 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元组
Python3
# 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