linspace
- paddle. linspace ( start: float | paddle.Tensor, stop: float | paddle.Tensor, num: int | paddle.Tensor, dtype: DTypeLike | None = None, name: str | None = None, *, out: paddle.Tensor | None = None, device: PlaceLike | None = None, requires_grad: bool = False ) paddle.Tensor [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
startis 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
stopis 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
numis given num of the sequence. It is an int, or a 0-D Tensor with data type int32.dtype (str|paddle.dtype|np.dtype|None, 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|None, optional) – For details, please refer to api_guide_Name. Generally, no setting is required. Default: None.
out (Tensor|None, optional) – Optional output tensor. If provided, the result will be stored in this tensor. The tensor must have the correct shape and dtype. Default: None.
device (str|paddle.CUDAPlace|paddle.CPUPlace|None, optional) – The device where the output tensor will be placed. It can be a string (e.g., ‘cpu’, ‘gpu:0’), a paddle.CUDAPlace, or a paddle.CPUPlace object. If None, the current device context will be used. Default: None.
requires_grad (bool, optional) – Whether the output tensor should have gradient computation enabled. If True, the output tensor’s
stop_gradientattribute will be set to False. Default: False.
- 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
numis set 1, the output tensor just has the value with inputstart. - Return type
-
Tensor
Note
Alias Support:
The parameter name
endcan be used as an alias forstop. For example,linspace(start=0, end=10, ...)is equivalent tolinspace(start=0, stop=10, ...).The parameter name
stepscan be used as an alias fornum. For example,linspace(start=0, stop=10, steps=5)is equivalent tolinspace(start=0, stop=10, num=5).
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.] >>> # Using device parameter >>> data = paddle.linspace(0, 10, 5, device='cpu') >>> print(data.numpy()) [0. 2.5 5. 7.5 10.] >>> # Using requires_grad parameter >>> data = paddle.linspace(0, 10, 5, requires_grad=True) >>> print(data.stop_gradient) False
