torch.linspace(start, end, steps=100, out=None) → Tensor
返回一個1維張量,包含在區間start和end上均勻間隔的step個點。
輸出張量的長度由steps決定。
參數:
- start (float) - 區間的起始點
- end (float) - 區間的終點
- steps (int) - 在start和end間生成的樣本數
- out (Tensor, optional) - 結果張量
而這個分割的間距是 (end - start)/ (steps - 1)
例如:torch.linspace(1,10, 6) 他的分割量 = (end - start)/ (steps - 1) = (10 - 1) / (6 - 1) = 1.8,那么結果就會是1, 1 + 1.8 * 1 = 2.8, 1 + 1.8 * 2 = 4.6, , 1 + 1.8 * 3 = 6.4, 1 + 1.8 * 4 = 8.2,1 + 1.8 * 5 = 10
編譯器打印結果為:tensor([ 1.0000, 2.8000, 4.6000, 6.4000, 8.2000, 10.0000]),與計算結果一致
