TensorFlow是Google設計的開源Python庫,用於開發機器學習模型和深度學習神經網絡。
constant_initializer()是生成具有恒定值的Tensor的初始化程序。
用法:tensorflow.constant_initializer( value )
參數:
- value:它是需要轉換為張量的值。它可以是Python標量,值的列表或元組,或者是N-dimensional numpy數組
返回值:它返回一個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)
輸出:
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
相關用法
注:本文由純淨天空篩選整理自aman neekhara大神的英文原創作品 Python – tensorflow.constant_initializer()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。