#merge or split
# Cat Stack Split Chunk
import torch
a=torch.rand(4,32,8)
b=torch.rand(5,32,8)
print(torch.cat([a,b],dim=0).shape)
a1=torch.rand(4,3,16,32)
a2=torch.rand(4,3,16,32)
print(torch.stack([a1,a2],dim=2).shape)#添加一个新维度
#split:bylen
#Chunk:by num
# 基本运算
#Math operation
a=torch.rand(3,4)
b=torch.rand(4)#broadcast
print(a,b)
print(a+b)
torch.add(a,b)
torch.all(torch.eq(a-b,torch.sub(a,b)))#所有位置都相等返回1
torch.matmul(a,b) a@b#矩阵相乘
a=torch.full([2,2],3)
a.pow(2)
a=torch.exp(torch.ones(2,2))
torch.log(a)#log2()
a=torch.full([8],1)
b=a.view(2,4)
c=a.view(2,2,2)
a.norm(1,dim=1)
a.topk(3,dim=1,largest=False)
torch.equal(a,a)
#torch.where(cond>0.5,a,b)
2021-03-09
最新推荐文章于 2022-03-17 14:39:48 发布