# tf.ones

<br />

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

Creates a tensor with all elements set to 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=tf.dtypes.float32, name=None
    )

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

#### For example:

    tf.ones([2, 3], tf.int32)  # [[1, 1, 1], [1, 1, 1]]

<br />

<br />

<br />

| ## Args ||
|---|---|
| `shape` | A list of integers, a tuple of integers, or a 1-D `Tensor` of type `int32`. |
| `dtype` | The type of an element in the resulting `Tensor`. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

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

<br />