import torch
#张量初始化
# print ('一般性初始化:', torch.tensor([1,2,3]))
# print('随机初始化:', torch.arange(0,4,step = 1))
# print('随机初始化:',torch.range(0,3,step = 1))
# the step is the skipwindow
# print('随机初始化:',torch.linspace(0,3,steps = 4))
# print('随机初始化:',torch.logspace(0,3,steps = 4))
# the steps is numbers
# weight = torch.full((3,4), 0.6)
# # the percentage args
# print(torch.bernoulli(weight))
# # generate 0 or 1
# # weights = torch.tensor([[1,100],[100,1],[1,1]],dtype = torch.float32)
# # print (torch.mutinormal(weights,1))
# # the weight and the select times
# print('生成随机序列:',torch.randperm(10))
# # 0 - 9 without sort tensor
# print('生成均匀分布:',torch.randint(low = 0, high = 4, size = (3, 4)))
# print('生成均匀分布:',torch.randint_like(torch.ones(3, 4), low = 0, high = 4))
# # include low but without high
#
pytorch 基本数据初始化
最新推荐文章于 2024-05-07 16:08:47 发布
本文详细介绍了PyTorch中如何初始化张量和其他基本数据类型,包括随机数生成、常数值设置以及从文件加载数据的方法。通过实例演示,帮助读者掌握在PyTorch中有效地初始化模型权重和输入数据的关键技巧。
摘要由CSDN通过智能技术生成