pytorch中的切片操作与索引方法
发布时间
阅读量:
阅读量
import torch
import numpy as np
切片与索引
a = torch.randint(1,10,[4,3,5,5]) #4张图片,3个通道,长和宽都是28个pixel
a[0].shape #第一张图片的尺寸 0表示第一张
torch.Size([3, 5, 5])
a[1,2].shape #第二张图片,第三个通道的尺寸
torch.Size([5, 5])
a[:,1] #生成一个4*28*28的tensor 取出每张照片第一个通道的所有内容
tensor([[[9, 8, 7, 7, 8],
[1, 5, 6, 6, 3],
[5, 4,
全部评论 (0)
还没有任何评论哟~
