Conv1D layer input and output

Consider the following code for Conv1D layer

# The inputs are 128-length vectors with 10 timesteps, and the batch size
# is 4.
input_shape = (4, 10, 128)
x = tf.random.normal(input_shape)
y = tf.keras.layers.Conv1D(32, 3, activation='relu',input_shape=input_shape[1:])(x)
print(y.shape)
(4, 8, 32)


It has been given that there are 10 vectors, with each of length 128. Then how does the output will be of shape (8, 32)?

If we apply a filter of size 3, we will then get a vector of length 126, if stride is 1. But, I cannot see 126 anywhere in the output.

How to understand the shapes of input and output?

• Please consider upvoting the answer if you found it useful, and also mark it as correct if deemed so. Alternatively, please comment on what you think the answer lacks or what is not clear. – noe Feb 24 at 18:46
• @noe thanks for providing an answer. I require some more knowledge to appreciate the answer. In search of the knowledge. – hanugm Feb 25 at 4:57