这里写自定义目录标题
python语法:
1.enumerate多用于在for循环中得到计数,利用它可以同时获得索引和值,即需要index和value值的时候可以使用enumerate
enumerate()返回的是一个enumerate对象
s = [1, 2, 3, 4, 5]
e = enumerate(s)
for index, value in e:
print(‘%s, %s’ % (index, value))
输出结果:
0, 1
1, 2
2, 3
3, 4
4, 5
squeeze(-1) 会删除张量中最后一个维度上大小为1的任何维度。例如,如果张量的形状为 (3, 4, 1),squeeze(-1) 将返回形状为 (3, 4) 的张量。
transpose(-1, -2) 交换张量中倒数第一和倒数第二个维度。例如,如果张量的形状为 (3, 4),transpose(-1, -2) 将返回形状为 (4, 3) 的张量。
因此,y.squeeze(-1).transpose(-1, -2) 将删除张量 y 中最后一个维度上大小为1的任何维度,然后交换结果张量的最后两个维度。
.unsqueeze(-1) is a PyTorch tensor method that adds an additional dimension of size 1 at the end of the tensor.
For example, if a tensor x has shape (3, 4), x.unsqueeze(-1) will return a tensor with shape (3, 4, 1).