TF Constants and Variables
Learn about TF constants and variables and their uses.
We'll cover the following
In TF2, tensors can be of two types: constant or variable. However, TF1 supports placeholders for its default graph execution mode. Here, we explain some properties of both constants and variables.
TF constants
We can create immutable tensors with tf.constant()
, where tf
is an alias for TensorFlow. To generate a constant tensor, we can write tf.constant(15)
. If we type tf.constant([6., 4., 3.], [5., 1., 2.])
, we create a floating-point matrix with two rows and three columns.
We can apply mathematical operations, such as addition, subtraction, multiplication, division, and square, to TF constant tensors. Indexing can also be performed on constant tensors, just like on NumPy arrays.
Get hands-on with 1400+ tech skills courses.