pytorch 实现删除tensor中的指定行列
作者:qq_29007291 时间:2023-05-22 14:26:26
前言
在pytorch中, 想删除tensor中的指定行列,原本以为有个函数或者直接把某一行赋值为[]就可以,结果发现没这么简单,因此用了一个曲线救国方法,希望如果有更直接的方法,请大家指出。
code
本质上是利用mask删除了指定行,然后重新指向。
a = torch.rand(4, 2)
print(a)
idx = 1
a = a[torch.arange(a.size(0))!=1]
print(a)
"""
tensor([[2.7775e-01, 3.7430e-01],
[9.0373e-01, 8.1220e-02],
[9.8638e-01, 8.6293e-01],
[9.8139e-04, 9.8460e-02]])
tensor([[2.7775e-01, 3.7430e-01],
[9.8638e-01, 8.6293e-01],
[9.8139e-04, 9.8460e-02]])
"""
来源:https://blog.csdn.net/qq_29007291/article/details/91042899
标签:pytorch,删除,tensor,行列
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python 字典和列表嵌套用法详解
2022-04-12 10:58:12
python中如何使用正则表达式的集合字符示例
2022-05-31 13:00:56
遗传算法python版
2021-04-29 23:36:20
![](https://img.aspxhome.com/file/2023/5/127685_0s.jpg)
Python实现账号密码输错三次即锁定功能简单示例
2023-07-22 07:40:21
golang中使用匿名结构体的方法
2023-07-10 07:26:56
python字典序问题实例
2023-07-31 05:46:58
FrontPage XP设计教程1——站点初建与管理
2008-10-11 12:13:00
![](https://img.aspxhome.com/file/UploadPic/200810/17/20081017121637930.jpg)
MySQL批量SQL插入性能优化详解
2024-01-21 15:25:59
![](https://img.aspxhome.com/file/2023/8/119708_0s.jpg)
Python运算符+与+=的方法实例
2022-02-26 04:40:59
Python中断言Assertion的一些改进方案
2023-03-05 15:07:57
JS实现十字坐标跟随鼠标效果
2024-04-22 22:43:00
![](https://img.aspxhome.com/file/2023/9/135569_0s.jpg)
python+numpy+matplotalib实现梯度下降法
2023-07-26 04:07:35
![](https://img.aspxhome.com/file/2023/8/95918_0s.gif)
YUV转为jpg图像的实现
2021-07-26 09:18:29
CentOS下安装python3.5+scrapy的方法步骤
2022-07-17 20:01:42
如何免费获取 Jetbrain 全家桶使用兑换码的正确姿势(推荐)
2023-10-17 11:53:15
![](https://img.aspxhome.com/file/2023/2/117532_0s.jpg)
python实现五子棋算法
2022-12-22 18:53:15
![](https://img.aspxhome.com/file/2023/4/133444_0s.gif)
Golang切片和数组拷贝详解(浅拷贝和深拷贝)
2024-04-26 17:20:38
![](https://img.aspxhome.com/file/2023/2/134252_0s.png)
oracle 常用的几个SQL
2009-12-01 12:36:00
6个卓越Web设计细节[译]
2010-03-24 18:34:00
![](https://img.aspxhome.com/file/UploadPic/20103/24/01-28s.jpg)
python 从远程服务器下载日志文件的程序
2021-03-06 01:39:15