问题描述
神の代码秀我一脸,来搞懂一下
问题解决
1. torch.tensor的bool索引
作用:只保留为true或为1位置处的元素
参考:https://deepinout.com/pytorch/pytorch-questions/117_pytorch_can_i_slice_tensors_with_logical_indexing_or_lists_of_indices.html
2. torch.tensor中None的使用
作用:*增加维度,有几个None就是增加几个维度
参考:https://blog.csdn.net/flyingluohaipeng/article/details/125093683
new_x1 = x[None,:,:]
new_x2 = x[:,None,:]
new_x3 = x[:,:,None]
print('-------new_x1--------')
print(new_x1)
print(new_x1.shape)
print('-------new_x2--------')
print(new_x2)
print(new_x2.shape)
print('-------new_x3--------')
print(new_x3)
print(new_x3.shape)
3. torch中逻辑运算的广播机制
4. ~是python的按位取反运算符
作用:按位取反
参考:https://www.runoob.com/python/python-operators.html