<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/ops/array_ops.py#L204-L250) |

Creates a tensor filled with a scalar value.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.fill`](https://www.tensorflow.org/api_docs/python/tf/fill)

<br />

    tf.fill(
        dims, value, name=None, layout=None
    )

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Ragged tensors](https://www.tensorflow.org/guide/ragged_tensor) - [tf.data: Build TensorFlow input pipelines](https://www.tensorflow.org/guide/data) - [Subword tokenizers](https://www.tensorflow.org/text/guide/subwords_tokenizer) - [Unicode strings](https://www.tensorflow.org/text/guide/unicode) | - [Scalable model compression](https://www.tensorflow.org/tutorials/optimization/compression) - [Multiple changepoint detection and Bayesian model selection](https://www.tensorflow.org/probability/examples/Multiple_changepoint_detection_and_Bayesian_model_selection) - [Graph-based Neural Structured Learning in TFX](https://www.tensorflow.org/tfx/tutorials/tfx/neural_structured_learning) - [Graph regularization for sentiment classification using synthesized graphs](https://www.tensorflow.org/neural_structured_learning/tutorials/graph_keras_lstm_imdb) - [Bayesian Gaussian Mixture Model and Hamiltonian MCMC](https://www.tensorflow.org/probability/examples/Bayesian_Gaussian_Mixture_Model) |

See also [`tf.ones`](https://www.tensorflow.org/api_docs/python/tf/ones), [`tf.zeros`](https://www.tensorflow.org/api_docs/python/tf/zeros), [`tf.one_hot`](https://www.tensorflow.org/api_docs/python/tf/one_hot), [`tf.eye`](https://www.tensorflow.org/api_docs/python/tf/eye).

This operation creates a tensor of shape `dims` and fills it with `value`.

#### For example:

    tf.fill([2, 3], 9)
    <tf.Tensor: shape=(2, 3), dtype=int32, numpy=
    array([[9, 9, 9],
           [9, 9, 9]], dtype=int32)>

[`tf.fill`](https://www.tensorflow.org/api_docs/python/tf/fill) evaluates at graph runtime and supports dynamic shapes based on
other runtime `tf.Tensors`, unlike [`tf.constant(value, shape=dims)`](https://www.tensorflow.org/api_docs/python/tf/constant), which
embeds the value as a `Const` node.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `dims` | A 1-D sequence of non-negative numbers. Represents the shape of the output [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor). Entries should be of type: `int32`, `int64`. |
| `value` | A value to fill the returned [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor). |
| `name` | Optional string. The name of the output [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor). |
| `layout` | Optional, [`tf.experimental.dtensor.Layout`](https://www.tensorflow.org/api_docs/python/tf/experimental/dtensor/Layout). If provided, the result is a [DTensor](https://www.tensorflow.org/guide/dtensor_overview) with the provided layout. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A [`tf.Tensor`](https://www.tensorflow.org/api_docs/python/tf/Tensor) with shape `dims` and the same dtype as `value`. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `InvalidArgumentError` | `dims` contains negative entries. |
| `NotFoundError` | `dims` contains non-integer entries. |

<br />

<br />

## numpy compatibility

<br />

Similar to `np.full`. In `numpy`, more parameters are supported. Passing a
number argument as the shape (`np.full(5, value)`) is valid in `numpy` for
specifying a 1-D shaped result, while TensorFlow does not support this syntax.

<br />

<br />