torch.logspace#
- torch.logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) Tensor #
创建一个一维张量,其大小为
steps
,值在对数刻度上从 到 之间均匀分布,包括端点,对数底数为base
。也就是说,这些值为从 PyTorch 1.11 开始,logspace 需要 steps 参数。使用 steps=100 以恢复之前的行为。
- 参数
- 关键字参数
out (Tensor, optional) – 输出张量。
dtype (torch.dtype, 可选) – 执行计算的数据类型。默认值:如果为 None,当
start
和end
都是实数时,使用全局默认 dtype(参见 torch.get_default_dtype());当其中任何一个为复数时,使用对应的复数 dtype。layout (
torch.layout
, 可选) – 返回张量的期望布局。默认值:torch.strided
。device (
torch.device
, 可选) – 返回张量的期望设备。默认值:如果为None
,则使用默认张量类型的当前设备(参见torch.set_default_device()
)。device
对于 CPU 张量类型将是 CPU,对于 CUDA 张量类型将是当前的 CUDA 设备。requires_grad (bool, 可选) – 如果自动梯度应该记录返回张量上的操作。默认值:
False
。
示例
>>> torch.logspace(start=-10, end=10, steps=5) tensor([ 1.0000e-10, 1.0000e-05, 1.0000e+00, 1.0000e+05, 1.0000e+10]) >>> torch.logspace(start=0.1, end=1.0, steps=5) tensor([ 1.2589, 2.1135, 3.5481, 5.9566, 10.0000]) >>> torch.logspace(start=0.1, end=1.0, steps=1) tensor([1.2589]) >>> torch.logspace(start=2, end=2, steps=1, base=2) tensor([4.0])