What is the constant in the basis of TensorFlow
What is the constant in the TensorFlow foundation? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Here are several functions related to constants in TensorFlow:
Tf.constant # constant tensor
Conversion of tf.convert_to_tensor # to tensor
Tf.range # integer equalization
Tf.linspace # linear equipartition
Tf.random.uniform # uniformly distributed
Tf.random.normal # normal distribution
Demonstration 1:
Import numpy as np
Import tensorflow as tf
G = tf.Graph ()
With g.as_default ():
# tf.constant can create a constant tensor
A = tf.constant ([1, 2, 3], dtype = tf.int32)
# tf.convert_to_tensor has a similar effect
# you can convert Python lists or numpy arrays into constant tensors
B = tf.convert_to_tensor ([1, 2, 3], preferred_dtype = tf.float32)
With tf.Session (graph = g) as sess:
Print (sess.run ({'afiuzhuajiajianglu b}))
The output is as follows:
Demonstration 2:
Import tensorflow as tf
G = tf.Graph ()
With g.as_default ():
# tf.range creates an integer arithmetic sequence
# use syntax tf.range (start, limit=None, delta=1)
C = tf.range (1, 1, 12, 2)
# tf.linspace is a linear bisection function, which creates floating-point equidifference series
# use syntax tf.linspace (start, stop, num)
D = tf.linspace (0. 010. 0. 9)
With tf.Session (graph = g) as sess:
Print (sess.run ({'cantilly}))
Print (sess.run ({'danghvvld}))
The output is as follows:
Demonstration 3:
Import tensorflow as tf
G = tf.Graph ()
With g.as_default ():
# tf.random.uniform creates a tensor with uniform distribution of element values
U = tf.random.uniform (shape= [3pr 3], minval=0,maxval=5,dtype=tf.int32)
# tf.random.normal creates a tensor for normal distribution of element values
V = tf.random.normal (shape= [6], mean= 0.0meme stddevau1.0 dtypewriter tf.float32)
With tf.Session (graph = g) as sess:
Print ('u =\ nSess.run (u))
Print ('v =\ nSess.run (v))
The output is as follows:
In addition, there are many functions similar to those in numpy that can be used to create constant tensors.
For example, tf.zeros,tf.ones,tf.zeros_like,tf.diag...
After reading the above, have you mastered the method of what the constants are in the foundation of TensorFlow? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!