今天看MDNet中看见,samples[:, 2:] *= self.aspect ** ratio不是很明白samples[:, 2:]是如何取值的。写了几个python语句大致是明白了。
逗号前面代表第一维,逗号后面代表第二维。冒号前面是起始位置,冒号后面是结束位置
1.a[:,2:]
a = np.array([1,2,3,4])
a = np.tile(a,(5,1))
print("原数组\n",a)
a[:,2:] *=2#第一维全部取,第二维从下标为2的开始取,取到最后,然后让这些元素自身乘以2
print("变换后的数组\n",a)
'''
原数组
[[1 2 3 4]
[1 2 3 4]
[1 2 3 4]
[1 2 3 4]
[1 2 3 4]]
变换后的数组
[[1 2 6 8]
[1 2 6 8]
[1 2 6 8]
[1 2 6 8]
[1 2 6 8]]
'''
2.a[:,0:2]
a = np.array([1,2,3,4])
a = np.tile(a,(5,1))
print("原数组\n",a)
a[:,0:2] *=2#第一维全部取,第二维从第0列开始选,选到第二列,然后让其乘以2,这个语句等价a[:,:2]
print("变换后的数组\n",a)
'''
原数组
[[1 2 3 4]
[1 2 3 4]
[1 2 3 4]
[1 2 3 4]
[1 2 3 4]]
变换后的数组
[[2 4 3 4]
[2 4 3 4]
[2 4 3 4]
[2 4 3 4]
[2 4 3 4]]
'''
3.a[1:3,:]
a = np.array([1,2,3,4])
a = np.tile(a,(5,1))
print("原数组\n",a)
a[1:3,:] *=2#第一维选取1,2行,第二维全部选。让其乘以2
print("变换后的数组\n",a)
'''
原数组
[[1 2 3 4]
[1 2 3 4]
[1 2 3 4]
[1 2 3 4]
[1 2 3 4]]
变换后的数组
[[1 2 3 4]
[2 4 6 8]
[2 4 6 8]
[1 2 3 4]
[1 2 3 4]]
'''