# tf.fill

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 1 version](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/fill) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.5.0/tensorflow/python/ops/array_ops.py#L200-L241) |

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
    )

See also [`tf.ones`](https://www.tensorflow.org/versions/r2.5/api_docs/python/tf/ones), [`tf.zeros`](https://www.tensorflow.org/versions/r2.5/api_docs/python/tf/zeros), [`tf.one_hot`](https://www.tensorflow.org/versions/r2.5/api_docs/python/tf/one_hot), [`tf.eye`](https://www.tensorflow.org/versions/r2.5/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/versions/r2.5/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/versions/r2.5/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/versions/r2.5/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/versions/r2.5/api_docs/python/tf/Tensor). |
| `name` | Optional string. The name of the output [`tf.Tensor`](https://www.tensorflow.org/versions/r2.5/api_docs/python/tf/Tensor). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A [`tf.Tensor`](https://www.tensorflow.org/versions/r2.5/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 />

#### Numpy Compatibility

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.