<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/math_ops.py#L113-L230) |

Generates evenly-spaced values in an interval along a given axis.

#### View aliases


**Compat aliases for migration**

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

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

<br />

    tf.linspace(
        start, stop, num, name=None, axis=0
    )

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Multilayer perceptrons for digit recognition with Core APIs](https://www.tensorflow.org/guide/core/mlp_core) - [Advanced automatic differentiation](https://www.tensorflow.org/guide/advanced_autodiff) - [Introduction to gradients and automatic differentiation](https://www.tensorflow.org/guide/autodiff) - [Basic training loops](https://www.tensorflow.org/guide/basic_training_loops) - [TensorFlow basics](https://www.tensorflow.org/guide/basics) | - [Integrated gradients](https://www.tensorflow.org/tutorials/interpretability/integrated_gradients) - [Learned data compression](https://www.tensorflow.org/tutorials/generative/data_compression) - [Basic regression: Predict fuel efficiency](https://www.tensorflow.org/tutorials/keras/regression) - [Scalable model compression](https://www.tensorflow.org/tutorials/optimization/compression) - [TFP Release Notes notebook (0.12.1)](https://www.tensorflow.org/probability/examples/TFP_Release_Notebook_0_12_1) |

A sequence of `num` evenly-spaced values are generated beginning at `start`
along a given `axis`.
If `num > 1`, the values in the sequence increase by
`(stop - start) / (num - 1)`, so that the last one is exactly `stop`.
If `num <= 0`, `ValueError` is raised.

Matches
[np.linspace](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html)'s
behaviour
except when `num == 0`.

#### For example:

    tf.linspace(10.0, 12.0, 3, name="linspace") => [ 10.0  11.0  12.0]

`Start` and `stop` can be tensors of arbitrary size:

    tf.linspace([0., 5.], [10., 40.], 5, axis=0)
    <tf.Tensor: shape=(5, 2), dtype=float32, numpy=
    array([[ 0.  ,  5.  ],
           [ 2.5 , 13.75],
           [ 5.  , 22.5 ],
           [ 7.5 , 31.25],
           [10.  , 40.  ]], dtype=float32)>

`Axis` is where the values will be generated (the dimension in the
returned tensor which corresponds to the axis will be equal to `num`)

    tf.linspace([0., 5.], [10., 40.], 5, axis=-1)
    <tf.Tensor: shape=(2, 5), dtype=float32, numpy=
    array([[ 0.  ,  2.5 ,  5.  ,  7.5 , 10.  ],
           [ 5.  , 13.75, 22.5 , 31.25, 40.  ]], dtype=float32)>

<br />

<br />

<br />

| ## Args ||
|---|---|
| `start` | A `Tensor`. Must be one of the following types: `bfloat16`, `float32`, `float64`. N-D tensor. First entry in the range. |
| `stop` | A `Tensor`. Must have the same type and shape as `start`. N-D tensor. Last entry in the range. |
| `num` | A `Tensor`. Must be one of the following types: `int32`, `int64`. 0-D tensor. Number of values to generate. |
| `name` | A name for the operation (optional). |
| `axis` | Axis along which the operation is performed (can be specified to non-zero only when N-D tensors are provided). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor`. Has the same type as `start`. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `InvalidArgumentError` | If `axis` is specified to non-zero when 1-D tensor is provided. |

<br />