Pytorch笔记——2.Pytorch常见函数
一、tensor属性类
1.tensor.dim()
查看tensor的维度。
示例:
import torch
import numpy as np
# 定义一个3维向量
a = torch.tensor(np.random.rand(24).reshape(2,3,4), dtype=torch.float)
print(a)
# 打印tensor的维度
print(a.dim())
2.tensor.size()
查看tensor的大小。
import torch
import numpy as np
# 定义一个3维向量
a = torch.tensor(np.random.rand(24).reshape(2,3,4), dtype=torch.float)
print(a)
# 查看tensor的大小
print(a.size())
3.tensor.shape
查看tensor的形状。
import torch
import numpy as np
# 定义一个3维向量
a = torch.tensor(np.random.rand(24).reshape(2,3,4), dtype=torch.float)
print(a)
# 查看tensor的形状
print(a.shape)
还没有评论,来说两句吧...