Numerical grids
Create coordinate values for plotting or evaluating a function over a bounded interval.
TensorFlow · Function
Generates a tensor of evenly spaced values between start and stop along a chosen axis. For more than one value, the sequence ends exactly at stop.
The function creates a sequence containing num evenly spaced values beginning at start and ending at stop when num is greater than one. For multidimensional inputs, axis determines the output dimension whose size becomes num; with num less than or equal to zero, it raises ValueError.
tf.linspace(start, stop, num, name=None, axis=0)| Name | Type | Description |
|---|---|---|
start | Tensor | A floating-point N-D tensor providing the first value in the range. Supported types are bfloat16, float32, and float64. |
stop | Tensor | A tensor with the same type and shape as start, providing the last value in the range. |
num | Tensor | A scalar integer tensor specifying the number of values to generate. Supported types are int32 and int64. |
name | string | Optional operation name. |
axis | int | Axis along which values are generated for N-D inputs; defaults to 0. |
A tensor containing num evenly spaced values generated from start to stop along axis.
import tensorflow as tf
values = tf.linspace(10.0, 12.0, 3)
print(values.numpy()) # [10. 11. 12.]Creates three evenly spaced values from 10.0 through 12.0, including both endpoints.
Create coordinate values for plotting or evaluating a function over a bounded interval.
Generate matching sequences across vector or matrix endpoints while preserving batch dimensions.
Construct evenly spaced inputs for interpolation or sampling procedures.
tf.linspace generates num evenly spaced values from start toward stop. When num is greater than one, the increment is (stop - start) / (num - 1), making stop the final value.
Follow-up: What happens when num is one? The sequence contains one generated value; the documented increment rule applies only when num is greater than one.
start and stop must be tensors with supported floating-point types and matching shape. num is a scalar integer tensor specifying how many values to generate.
Follow-up: What shape does num have? It must be a 0-D tensor, unlike start and stop, which may be N-D.
axis controls where the generated sequence is inserted when start and stop are N-D tensors. The corresponding output dimension has size num.
Follow-up: What is the default axis? axis defaults to 0, so the generated dimension is placed first unless another axis is supplied.
tf.keras.ops.linspacetf.experimental.numpy.linspacetf.Tensor