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]),与计算结果一致