linspace

paddle. linspace ( start, stop, num, dtype=None, name=None ) [source]

Return fixed number of evenly spaced values within a given interval. Note: no gradient calculation is performed.

Parameters
  • start (int|float|Tensor) – The input start is start of range. It is a int, float, or a 0-D Tensor with data type int32, int64, float32 or float64.

  • stop (int|float|Tensor) – The input stop is end of range. It is a int, float, or a 0-D Tensor with data type int32, int64, float32 or float64.

  • num (int|Tensor) – The input num is given num of the sequence. It is an int, or a 0-D Tensor with data type int32.

  • dtype (np.dtype|str, optional) – The data type of output tensor, it could be int32, int64, float32 and float64. Default: if None, the data type is float32.

  • name (str, optional) – For details, please refer to Name. Generally, no setting is required. Default: None.

Returns

the output data type will be float32, float64. The 1-D tensor with fixed number of evenly spaced values, the data shape of this tensor is \([num]\) . If the num is set 1, the output tensor just has the value with input start.

Return type

Tensor

Examples

>>> import paddle
>>> data = paddle.linspace(0, 10, 5, 'float32')
>>> print(data.numpy())
[0. 2.5 5. 7.5 10.]
>>> data = paddle.linspace(0, 10, 1, 'float32')
>>> print(data.numpy())
[0.]

Used in the guide/tutorials