Python – tensorflow.constant_initializer()

TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks.
constant_initializer() is initializer that generate a Tensor with constant value.
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.
Example 1: From Python list
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) |
Output:
l: [1, 2, 3, 4] x: tensorflow.python.ops.init_ops_v2.Constant object at 0x7fa7f2e1ab00
Example 2: From Python tuple
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) |
Output:
l: (1, 2, 3, 4) x: tensorflow.python.ops.init_ops_v2.Constant object at 0x7fa7f2e1ab00



