Tensor初始化
1 | //1 数组 -> Tensor |
Tensor 操作
index_select
提取指定元素形成新的张量(关键字index:就代表是提取出来相应的元素组成新的张量)
1 | std::cout<<b.index_select(0,torch::tensor({0, 3, 3})).sizes();//选择第0维的0,3,3组成新张量[3,3,28,28] |
torch::topk
1 | torch::Tensor torch::topk(const torch::Tensor& input, int k, int dim=-1, bool largest=true, bool sorted=false) |
E2:
1 | torch::Tensor scores = torch::rand({10}); |