In this video, we're going to transfer a 1-D tensor to a vector using the tf.squeeze transformation to remove the dimension of size 1 from the shape of the tensor.
In order to do that, let's start by defining a TensorFlow variable that will hold random numbers between 0 and 10 that are of the data type 32-bit signed integers and has a shape of 1x5.
We create this tensor using the tf.get_variable operation and assign it to the Python variable, random_int_var_one_ex.
Let's print our random_int_var_one_ex Python variable to see what's in it.
We see the name of the tensor, we see the shape which is 1x5, and we see the data type is int32.
Now that we have created our TensorFlow variable, it's time to run the computational graph.
Then we initialize all the global variables in the graph, in this case just our random_int_var_one_ex tensor.
Let's print our random_int_var_one Python variable in a TensorFlow session to see the values.
We see 5, 3, 9, 2, 5 which is between 0 and 10, which is what we would expect.
The data type, it looks like they are integers.
Let's calculate the rank of the tensor to see what we get.
We use the tf.rank operation and we pass in our tensor.
We see that it is of rank 2 which means it is not a vector.
To make it a vector with a rank of 1, we'll use the tf.squeeze transformation to remove the dimension of size 1 from the shape of the tensor.
Here, we can see tf.squeeze and we pass in our tensor.
We can see visually that before, we had two square brackets on each side.
Now, we have one square bracket on each side.
And we see that it is 5, whereas before we knew that the shape was 1x5.
Which we can see when we get the shape of the random_int_var_one.
So it went from shape 1x5 to 5.
And we see that it is 1.
So it is now indeed a vector.
Finally, we close the TensorFlow session to release the TensorFlow resources we created within the session.
That is how you can transfer a 1-D tensor to a vector using the tf.squeeze transformation to remove the dimension of size 1 from the shape of the tensor.