Add a dimension to a tensorflow tensor
You can use tf.expand_dims(image, -1).

Given a tensor input, this operation inserts a dimension of length 1 at the dimension index axis of input's shape.
I got an image stack of 4 gray scale images which i want to pass to a neural network with tensorflow.
After reading in my 4 gray scale images and convert them to a tensor their shape is (4,120,160)
When i pass it to the neural network i get an error message. After some googling i found that i need the input shape of (4,120,160,1) in which the 1 stands for the color channel.
I have not found anyway to change the shape of my tensor in this way.
It seems to work with the expand dims function but it is a little bit cryptic for me to understand what it does.