文章目录
- 重塑维度 reshape / view
- 增加 / 减少维度 unsqueeze / squeeze
- 交换维度 transpose / permute
- 将维度扩充 Expand / repeat / broadcast
- transpose & view 的连续变化
- 张量比较使用 torch.all() & torch.eq()
重塑维度 reshape / view
增加 / 减少维度 unsqueeze / squeeze
交换维度 transpose / permute
- Permute 是一种更好的选择
- 底层也是使用 transpose 直到达到目的为止
- permute 也会打乱顺序,因此 view 之前也需要使用 contiguous
将维度扩充 Expand / repeat / broadcast
transpose & view 的连续变化
- 只要使用了 transpose,之后再想使用 view 一定要在 view 之前使用 contiguous
参考资料:bilibili https://www.bilibili.com/video/BV13a411u7G5?p=23&spm_id_from=pageDriver&vd_source=e162db2199c43956dc501bc6c0725612
张量比较使用 torch.all() & torch.eq()
- 判断两个张量是否是一样的