If you want to really understand slices, don’t have the concept of length, width and height. Instead, use the concept of dimensions.
The slicing method of three points '[,...]' in python The slicing method of three points `[,...]` in python P Y T H O n- in three th points ' [ ,. . . ] ' A cut sheet side of formula
The three points represent the operation on the lowest dimension, the so-called lowest dimension is the dimension X0 in the [Xn,Xn-1,...,X0] array
import torch
rgb = torch.randn(1, 3, 3, 4)
rgb
rgb.shape
rgb[...,1]
rgb[...,1].shape
rgb2 = torch.randn(3, 3, 4)
rgb2
rgb2[...,1]
rgb2[...,1].shape
import numpy
>>> a = numpy.array([[1,2,3,4,5],[6,7,8,9,10],[1,2,3,4,5],[6,7,8,9,10]])
>>> a
array([[ 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10],
[ 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10]])
>>> a[...,2] #表示遍历每行,2表示索引为2的所在列
array([3, 8, 3, 8])
>>> a[...,:2]#表示遍历每行,:2表示索引为<2的0,1所在的列
array([[1, 2],
[6, 7],
[1, 2],
[6, 7]])
>>> a[...,::2]#表示遍历每行,2表示步长,选取多索引为0,2,4所在的列
array([[ 1, 3, 5],
[ 6, 8, 10],
[ 1, 3, 5],
[ 6, 8, 10]])
a[None,...]#相当于插入维度,也想当于reshape(a,[1,4,4])
array([[[[ 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10],
[ 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10]]]])