python切片记录

import numpy as np
import torch
from torch.autograd import Variable 

import numpy as np
import torch
from torch.autograd import Variable 

x = Variable(torch.rand(5,5),requires_grad = False)
print(x)
print(x[:,0:1])
print(x[:,4:5])
print(x[:,4])
print(x[:,[-1]].shape)
'''
tensor([[0.0896, 0.1292, 0.2337, 0.8749, 0.7668],
        [0.7987, 0.5104, 0.9536, 0.2373, 0.1417],
        [0.6509, 0.8352, 0.9698, 0.4681, 0.8400],
        [0.2130, 0.5627, 0.5978, 0.9548, 0.8376],
        [0.9211, 0.0043, 0.6379, 0.0815, 0.1777]])
tensor([[0.0896],
        [0.7987],
        [0.6509],
        [0.2130],
        [0.9211]])
tensor([[0.7668],
        [0.1417],
        [0.8400],
        [0.8376],
        [0.1777]])
tensor([0.7668, 0.1417, 0.8400, 0.8376, 0.1777])
torch.Size([5, 1])
'''
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值