import torch
import numpy as np
# string 在torch中对string不支持,1 可以通过向量one-hot来进行分类
# 2 embedding word2vec glove
# type check
a = torch.randn(2, 3)
a.type()
# 'torch.FloatTensor'
type(a)
# <class 'torch.Tensor'>
isinstance(a, torch.FloatTensor)
# True
'''标量 ->dimension 0 tensor=0'''
a = torch.tensor(1.)
a.shape
# torch.Size([])
'''向量 ->dimension 1 tensor=1'''
a = torch.tensor([1.])
a.shape
# torch.Size([1])
torch.FloatTensor(2)
# 生成一个随机的torch.FloatTensor类型的一维张量(向量),这里2表示长度不是维度
data = np.ones(2)
a = torch.from_numpy(data)
# 从numpy中引入
pytorch基本用法_01
最新推荐文章于 2024-04-26 19:13:06 发布