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, optional) – 執行計算的資料型別。預設值:如果為 None,當
start和end都是實數時使用全域性預設 dtype (見 torch.get_default_dtype()),當其中任一是複數時使用對應的複數 dtype。layout (
torch.layout, optional) – 返回的張量的期望佈局。預設值:torch.strided。device (
torch.device, optional) – 返回的張量的期望裝置。預設值:如果None,則對預設張量型別使用當前裝置 (見torch.set_default_device())。對於 CPU 張量型別,device將是 CPU;對於 CUDA 張量型別,將是當前的 CUDA 裝置。requires_grad (bool, optional) – 如果 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])