2021-03-09

#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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值