Input shape clarification

Hi everyone,

I just started studying tensorflow recently and I am using a lot of resources and books on the internet.

I am familiarizing myself with shapes in a network, I actually have a good grasp of input shape when dealing with images: (28, 28) for one channel images, and (28,28,3) for RGB images (with three color channels)

However, when dealing with rectangular data (read from a CSV) I am a little bit confused

In the code below., I know that the [5] means 5 numerical features and [1] means 1 categorical feature only, my code works when training a model.

num_input = tf.keras.layers.Input(shape=[5], name='num')
cat_input = tf.keras.layers.Input(shape=[1], dtype=tf.string, name='cat')

However, the below still works when I replaced [1] with empty []

cat_input = tf.keras.layers.Input(shape=[1], dtype=tf.string, name='cat')

What does empty [] means? Could you give me some sort of explanation here that could be easily understood?

Thank you so much!

Shape indicates the shape of a input sample into the model/layers.
0D Tensors have shape=, basically are of scalars. e.g.

a=tf.convert_to_tensor(1)

here a is <tf.Tensor: shape=(), dtype=int32, numpy=1>
1D Tensors have shape=[n], where n can be any +ve number e.g. shape=[5] Tensor of numerical type can be produced as

b=tf.convert_to_tensor([10,30,45,51])

So

cat_input = tf.keras.layers.Input(shape=[], dtype=tf.string, name='cat')

means that single sample input would be tf.convert_to_tensor(“Hello, yo”)
whereas with shape=[1], it would be tf.convert_to_tensor([“Hello, yo”])
and with shape=[1,1], it would be tf.convert_to_tensor([[“Hi, no!”]])