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
都是實數時,使用全域預設資料類型 (參見 torch.get_default_dtype()),當其中一個是複數時,使用對應的複數資料類型。layout (
torch.layout
, optional) – 返回的 Tensor 的期望記憶體佈局。預設值:torch.strided
。device (
torch.device
, optional) – 返回的 tensor 的期望裝置。預設值:如果為None
,則使用預設 tensor 類型的當前裝置 (參見torch.set_default_device()
)。device
對於 CPU tensor 類型將會是 CPU,對於 CUDA tensor 類型將會是當前的 CUDA 裝置。requires_grad (bool, optional) – 如果 autograd 應該記錄在返回的 tensor 上的操作。預設值:
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])