Pytorch基础(6)——多项式函数拟合实验笔记

  • torch.cat((input1, input2, ... ), dim=?)

    torch.cat()可以将多个tensor在dim维度上进行拼接。如下:
    x1 = torch.tensor([[11,21,31],[21,31,41]],dtype=torch.int)
    
    x2 = torch.tensor([[12,22,32],[22,32,42]],dtype=torch.int)
    
    cat1 = torch.cat((x1, x2),0)
    cat2 = torch.cat((x1, x2),1)
    print(cat1,cat2)
    
    
    # 输出
    tensor([[11, 21, 31],
            [21, 31, 41],
            [12, 22, 32],
            [22, 32, 42]], dtype=torch.int32) tensor([[11, 21, 31, 12, 22, 32],
            [21, 31, 41, 22, 32, 42]], dtype=torch.int32)
  •  .shape[i]

    shape函数的功能是读取tensor某个维度的长度

        对于图像来说:

        image.shape[0]——图片高

        image.shape[1]——图片长

        image.shape[2]——图片通道数

        而对于矩阵来说:

        shape[0]:表示矩阵的行数

        shape[1]:表示矩阵的列数

        注:-1代表最后一个,所以shape[-1]代表最后一个维度,如在二维张量里,shape[-1]表示列数

x1 = torch.tensor([[11,21,31],[21,31,41]],dtype=torch.int)

print(x1.shape[0])
print(x1.shape[1])
print(x1.shape[-1])

# 输出
2
3
3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值