📜  Python – tensorflow.constant_initializer()

📅  最后修改于: 2022-05-13 01:55:06.917000             🧑  作者: Mango

Python – tensorflow.constant_initializer()

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

constant_initializer()是生成具有常量值的张量的初始化程序。

示例 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