0
0
TensorFlowml~10 mins

Tensor creation (constant, variable, zeros, ones) in TensorFlow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a constant tensor with value 5.

TensorFlow
import tensorflow as tf
const_tensor = tf.[1](5)
Drag options to blanks, or click blank then click option'
AVariable
Bzeros
Cones
Dconstant
Attempts:
3 left
💡 Hint
Common Mistakes
Using tf.Variable instead of tf.constant
Using tf.zeros or tf.ones which create tensors filled with 0 or 1
2fill in blank
medium

Complete the code to create a TensorFlow variable initialized with a list.

TensorFlow
import tensorflow as tf
var_tensor = tf.[1]([1, 2, 3])
Drag options to blanks, or click blank then click option'
AVariable
Bconstant
Czeros
Dones
Attempts:
3 left
💡 Hint
Common Mistakes
Using tf.constant instead of tf.Variable
Using tf.zeros or tf.ones which create tensors filled with 0 or 1
3fill in blank
hard

Fix the error in the code to create a tensor of zeros with shape (2, 3).

TensorFlow
import tensorflow as tf
zero_tensor = tf.zeros(shape=[1])
Drag options to blanks, or click blank then click option'
A(2, 3)
B[2, 3]
C2, 3
D{2, 3}
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces which define a set, not a shape tuple
Passing multiple arguments instead of a single shape tuple
4fill in blank
hard

Fill both blanks to create a tensor of ones with shape (3, 4) and data type float32.

TensorFlow
import tensorflow as tf
one_tensor = tf.[1](shape=[2], dtype=tf.float32)
Drag options to blanks, or click blank then click option'
Aones
Bzeros
C(3, 4)
D[3, 4]
Attempts:
3 left
💡 Hint
Common Mistakes
Using tf.zeros instead of tf.ones
Using a list instead of a tuple for shape
5fill in blank
hard

Fill all three blanks to create a variable tensor initialized with zeros of shape (2, 2) and integer type.

TensorFlow
import tensorflow as tf
var_zero_tensor = tf.[1](tf.[2](shape=[3], dtype=tf.int32))
Drag options to blanks, or click blank then click option'
AVariable
Bzeros
C(2, 2)
Dones
Attempts:
3 left
💡 Hint
Common Mistakes
Using tf.ones instead of tf.zeros
Not wrapping the tensor with tf.Variable
Using list instead of tuple for shape