PyTorch tensor 翻转

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

read: 2886

转自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 …

此站点由 ASP.NETIIS 驱动 | © 2018-2023 hupeng.me. All Rights Reserved.