PyTorch tensor 翻转

June 18, 2019, 5:33 p.m.

read: 245

转自https://discuss.pytorch.org/t/how-to-reverse-a-torch-tensor/382

形状为(10)的tensor翻转

tensor = torch.rand(10) # your tensor
# create inverted indices
idx = [i for i in range(tensor.size(0)-1, -1, -1)]
idx = torch.LongTensor(idx)
inverted_tensor = tensor.index_select(0, idx)

形状为(1,10,1)的tensor翻转

tensor = torch.rand(1, 10, 1) # your tensor
# create inverted indices
idx = [i for i in range(tensor.size(1)-1, -1, -1)]
idx = torch.LongTensor(idx)
inverted_tensor = tensor.index_select(1, idx)




评论

昵称:
邮箱:
内容:
评论

Vector Matrix Tensor

二进制文件转npy文件(Python3)

文章标题:二进制文件转npy文件(Python3)文章内容:以下demo只支持float格式,仅提供思路,其他数据类型需自行扩展: import numpy as np import struct …

推荐使用 Firefox 访问此站点 | 友情链接: 张鹏的博客  Web布拉格  杨洋的博客   李号的博客   魏文成博客 | Developed by zhangpeng && hupeng | Copyright © 2018-2019 hupeng.me