Let's start with constants:
- We can declare a scalar constant:
t_1 = tf.constant(4)
- A constant vector of shape [1,3] can be declared as follows:
t_2 = tf.constant([4, 3, 2])
- To create a tensor with all elements zero, we use tf.zeros(). This statement creates a zero matrix of shape [M,N] with dtype (int32, float32, and so on):
tf.zeros([M,N],tf.dtype)
Let's take an example:
zero_t = tf.zeros([2,3],tf.int32) # Results in an 2×3 array of zeros: [[0 0 0], [0 0 0]]
- We can also create tensor constants of the same shape as an existing Numpy array or tensor constant as follows:
tf.zeros_like(t_2) # Create a zero matrix of same shape as t_2 tf.ones_like(t_2) # Creates a ones matrix of same shape as t_2
- We can create a tensor ...