torch.linspace()用法

torch.linspace()用法

torch.linspace(start, end, steps=100, out=None, dtype=None, layout=torch.strided, device=None, requires_grad=False) → Tensor
函数的作用是,返回一个一维的tensor(张量),这个张量包含了从start到end(包括端点)的等距的steps个数据点。
常用的几个参数含义:

start:开始值

end:结束值

steps:分割的点数,默认是100

dtype:返回值(张量)的数据类型

举例:
import torch
print(torch.linspace(3,10,5))
结果:tensor([ 3.0000, 4.7500, 6.5000, 8.2500, 10.0000])

type=torch.float
print(torch.linspace(-10,10,steps=6,dtype=type))
结果:tensor([-10., -6., -2., 2., 6., 10.])

猜你喜欢

转载自blog.csdn.net/weixin_43255962/article/details/84347726