【笔记】pytorch语法 torch.repeat & torch.expand

torch.repeat 与 torch.expand 比较

torch.repeat和torch.expand的区别:
对比

与numpy类似函数的比较

torch.repeat

torch.repeat用法类似np.tile,同时numpy中也有一个repeat,用法对应torch中的 torch.repeat_interleave。
这两者的类似都是在参数层面和使用方法上的类似,torch.repeat和torch.repeat_interleave得到的结果与输入都没有关联。

torch.expand

torch.expand的结果与输入有关联,见上图中例子,类似numpy.broadcast_to。同时numpy.broadcast_to在使用方法上类似np.tile。

总结

torch.repeat与torch.expand的差异,类似np.tile与np.broadcast_to的差异。

torchnumpy是否broadcast参数类型和使用方法
torch.repeatnp.tileA
torch.expandnp.broadcast_toA
torch.repeat_interleavenp.repeatB
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值