数组的调用中经常会用到a[...,1]与a[...,1:2]最开始对这两种调用方法有点不是很明白,操作后如下:
1 import tensorflow as tf
2 import numpy as np
3 a = np.array([[[1,2,21],[3,4,34]],[[5,6,56],[7,8,78]]])
4 print('a.shape:',a.shape)
5
6 b = a[...,0:2]
7 print('b :',b)
8 print('shape.b:',b.shape)
结果如下:
a.shape: (2, 2, 3)
b : [[[1 2]
[3 4]]
[[5 6]
[7 8]]]
shape.b: (2, 2, 2)
但是如果用a[...,1],结果如下:
a.shape: (2, 2, 3)
b : [[2 4]
[6 8]]
shape.b: (2, 2)
可以看到[...,1:3]代表的时最后一维度中的1:3的数,输入为原先维度中最后一个维度的数组,而[...,2]则是-2维度中的信息,输入相对与原先的维度少了一个维度。