A tensor is a vector or matrix of n-dimensions that represents all types of data. All the values in a tensor are having the same data type known as shape. The shape is the dimension of any matrix.
To create a tensor, you can use tf.constant().
Here is the syntax for the same:
tf.constant(value, dtype, name = "")
The arguments are as follows:
-value: Value of n dimension to define the tensor. Optional
- dtype: Define the type of data:
- tf.string: String variable
- tf.float32: Float variable
- tf.int16: Integer variable
- "name": Name of the tensor.
To create a tensor of dimension 0, run the following code:
r1 = tf.constant(1, tf.int16)
You can define a tensor with decimal values or with a string by changing the type of data.
r1_decimal = tf.constant(0.9, tf.float32)
r1_string = tf.constant("any name", tf.string)
The following fill operation creates a tensor of shape dims and fills it with value.
Now for the specified shape, When you print the tensor, TensorFlow guesses the shape. However, you can get the shape of the tensor with the shape property.
m_shape = tf.constant(0.9, tf.float32)
Hope this helps!
Interested in learning Artificial Intelligence? Click to learn more artificial intelligence course.