Complete the code to create a tensor filled with zeros of shape (3, 3).
import tensorflow as tf zero_tensor = tf.[1](shape=(3, 3)) print(zero_tensor)
The tf.zeros function creates a tensor filled with zeros of the specified shape.
Complete the code to add two tensors element-wise.
import tensorflow as tf x = tf.constant([1, 2, 3]) y = tf.constant([4, 5, 6]) sum_tensor = tf.[1](x, y) print(sum_tensor)
The tf.add function adds two tensors element-wise.
Fix the error in the code to compute the matrix multiplication of two tensors.
import tensorflow as tf A = tf.constant([[1, 2], [3, 4]]) B = tf.constant([[5, 6], [7, 8]]) result = tf.[1](A, B) print(result)
The tf.matmul function performs matrix multiplication between two tensors.
Fill both blanks to create a tensor of shape (2, 3) filled with ones and then multiply it by 5.
import tensorflow as tf ones_tensor = tf.[1](shape=(2, 3)) scaled_tensor = ones_tensor [2] 5 print(scaled_tensor)
tf.ones creates a tensor filled with ones. Multiplying by 5 scales all elements by 5.
Fill both blanks to compute its square, and then find the mean of the squared values.
import tensorflow as tf x = tf.constant([1, 2, 3, 4]) squared = tf.math.[1](x) mean_val = tf.reduce_[2](squared) print(mean_val.numpy()) # Output the mean as a number
tf.math.square squares each element. tf.reduce_mean computes the average of all elements.