Understand the Shape or Dimension of a Scalar in TensorFlow – TensorFlow Tutorial

By | November 7, 2020

Scalar is a number, such as 1, 2, 3, 1.001. What’s the shape or dimension of it? In this tutorial, we will discuss this topic.

We will write an example first.

import tensorflow as tf 

t = tf.shape(c) # the shape of scalar
# Printing the result 
init = tf.global_variables_initializer() 
init_local = tf.local_variables_initializer()
with tf.Session() as sess:
    sess.run([init, init_local])

In this example, tensor c is a scalar, t is the shape of c.

Run this example, we can find the shape of scalar c is [], the dimension is 0.

Moreover, if you want create a random float in tensorlfow, you can view:

Create a Random Float Number in TensorFlow – TensorFlow Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *