libtorch 哪些函数比较常用?

torch::sort

    torch::Tensor x = torch::rand({ 3,3 });
    std::cout << x << std::endl;

    //排序操作 true 大到小排序,false 小到大排序
    auto out = x.sort(-1, true);

    std::cout << std::get<0>(out) << "\r\n" << std::get<1>(out) << std::endl;

输出如下:

 0.0855  0.4925  0.4323
 0.8314  0.8954  0.0709
 0.0996  0.3108  0.6845
[ Variable[CPUFloatType]{3,3} ]

 0.4925  0.4323  0.0855
 0.8954  0.8314  0.0709
 0.6845  0.3108  0.0996
[ Variable[CPUFloatType]{3,3} ]

 1  2  0
 1  0  2
 2  1  0
[ Variable[CPULongType]{3,3} ]

猜你喜欢

转载自www.cnblogs.com/cheungxiongwei/p/10721547.html
今日推荐