torch.logspace¶
- torch.logspace(start, end, steps, base=10.0, *, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) 张量¶
创建一个大小为
steps的一维张量,其值在 到 之间均匀分布,在以base为底的对数尺度上。即,这些值是:从 PyTorch 1.11 开始,logspace 需要 steps 参数。使用 steps=100 来恢复之前的行为。
- Parameters
- Keyword Arguments
输出 (张量, 可选) – 输出张量。
dtype (torch.dtype, 可选) – 执行计算的数据类型。 默认值:如果为 None,则使用全局默认 dtype(参见 torch.get_default_dtype()) 当
start和end都为实数时, 以及当其中任意一个为复数时,使用相应的复数 dtype。布局 (
torch.layout, 可选) – 返回张量的所需布局。 默认值:torch.strided。设备 (
torch.device, 可选) – 返回张量所需的设备。 默认值:如果None,则使用默认张量类型的当前设备 (参见torch.set_default_device())。device将是 CPU 用于 CPU 张量类型,以及当前 CUDA 设备用于 CUDA 张量类型。requires_grad (布尔值, 可选) – 如果 autograd 应该记录对返回张量的操作。默认值:
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])