What does TensorFlow shape ?, mean?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
When TensorFlow or Keras shows a shape such as (?,) or (None,), it is describing a one-dimensional tensor whose length is not fixed at graph construction time. The unknown dimension is not an error by itself. It usually means the model or function is designed to accept variable-sized input along that axis.
What the Symbols Mean
A tensor shape is a tuple of dimensions. In the shape (?,), there is only one dimension, so the tensor is a vector.
The question mark stands for an unknown size. In modern TensorFlow code you will more often see None, but the idea is the same: TensorFlow knows the rank, but not the exact length yet.
So this:
means:
- rank 1 tensor
- length not fixed yet
- values will be known only when real data is provided
Compare It with Other Common Shapes
A few examples make the notation clearer:
- '
(10,)means a vector with exactly 10 elements.' - '
(None,)means a vector with any length.' - '
(None, 10)means a matrix with an unknown number of rows and exactly 10 columns.' - '
(32, 10)means a matrix with a fixed batch of 32 rows and 10 columns.'
The last two are especially common in model code because the first dimension is often the batch size.
A Simple TensorSpec Example
TensorFlow uses unknown dimensions in signatures all the time.
This function accepts vectors of different lengths because the shape allows an unknown dimension.
Why Models Often Show None
Keras models frequently show None in summaries because the batch dimension is intentionally flexible.
The input shape in the summary will usually appear as (None, 10). That does not mean your data is broken. It means the model can process batches of any size, as long as each example has 10 features.
If you see only (None,), then the model or function is expecting a single vector axis rather than a two-dimensional feature matrix.
Unknown Does Not Mean Unlimited Magic
An unknown dimension is flexible, but it is not a license to pass incompatible shapes. TensorFlow still enforces the rest of the specification.
For example, if a function expects (None, 10), then this is valid:
but this is not:
The number of rows can vary, but the second dimension must still match 10.
Static Shape Versus Runtime Shape
TensorFlow distinguishes between:
- static shape, which is what the graph knows ahead of time
- runtime shape, which is what the concrete tensor actually has during execution
You can inspect both ideas in code:
x.shape is TensorFlow's static metadata. tf.shape(x) gives a tensor containing runtime dimension values.
Common Pitfalls
- Treating
?orNoneas an error message instead of a placeholder for an unknown dimension. - Forgetting that
(?,)is rank 1 and assuming it means a two-dimensional batch automatically. - Passing data with the wrong fixed dimensions just because one axis is unknown.
- Confusing static shape metadata with runtime values returned by
tf.shape. - Assuming old
?notation and modernNonenotation mean different concepts when they usually describe the same idea.
Summary
- '
(?,)or(None,)means a one-dimensional tensor with variable length.' - The unknown dimension is usually intentional, especially for flexible input sizes or batch dimensions.
- Rank still matters, so
(?,)is a vector, not a matrix. - TensorFlow allows unknown dimensions only where the rest of the shape contract is still satisfied.
- Read the whole shape tuple, not just the question mark, before deciding what the tensor represents.

