# tf.ones

<br />

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

Creates a tensor with all elements set to one (1).

#### View aliases


**Compat aliases for migration**

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

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

<br />

    tf.ones(
        shape,
        dtype=https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/dtypes#float32,
        name=None
    )

See also [`tf.ones_like`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/ones_like), [`tf.zeros`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/zeros), [`tf.fill`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/fill), [`tf.eye`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf/eye).

This operation returns a tensor of type `dtype` with shape `shape` and
all elements set to one.

    tf.ones([3, 4], tf.int32)
    <tf.Tensor: shape=(3, 4), dtype=int32, numpy=
    array([[1, 1, 1, 1],
           [1, 1, 1, 1],
           [1, 1, 1, 1]], dtype=int32)>

<br />

<br />

<br />

| ## Args ||
|---|---|
| `shape` | A `list` of integers, a `tuple` of integers, or a 1-D `Tensor` of type `int32`. |
| `dtype` | Optional DType of an element in the resulting `Tensor`. Default is [`tf.float32`](https://www.tensorflow.org/versions/r2.13/api_docs/python/tf#float32). |
| `name` | Optional string. A name for the operation. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor` with all elements set to one (1). ||

<br />