(五)索引与切片

2020-02-12  本文已影响0人  zelda2333

1. 索引

# [b, c,h, w]
a = torch.rand(4,3,28,28)  

取第0张图片

In [12]:   a[0].shape
Out[13]:   torch.Size([3, 28, 28])

取第0张图片的第0个通道

In [12]:   a[0, 0].shape
Out[13]:   torch.Size([28, 28])

取第0张图片的第0个通道的2行第4列的像素点

In [12]:   a[0, 0, 2, 4]
Out[13]:   tensor(0.8072)

2. select first/last N

a[:2] ==[0,2)


3. select by steps

4. select by specific index

4. select by mask

5. select by flatten index

上一篇 下一篇

猜你喜欢

热点阅读