Have a question? Connect with the community at the TensorFlow Forum

# tf.linspace

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

### Used in the notebooks

Used in the guide Used in the tutorials

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'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)>`
```

`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 (used only when N-D tensors are provided).

A `Tensor`. Has the same type as `start`.

[{ "type": "thumb-down", "id": "missingTheInformationINeed", "label":"没有我需要的信息" },{ "type": "thumb-down", "id": "tooComplicatedTooManySteps", "label":"太复杂/步骤太多" },{ "type": "thumb-down", "id": "outOfDate", "label":"内容需要更新" },{ "type": "thumb-down", "id": "samplesCodeIssue", "label":"Samples / code issue" },{ "type": "thumb-down", "id": "otherDown", "label":"其他" }]
[{ "type": "thumb-up", "id": "easyToUnderstand", "label":"易于理解" },{ "type": "thumb-up", "id": "solvedMyProblem", "label":"解决了我的问题" },{ "type": "thumb-up", "id": "otherUp", "label":"其他" }]