TensorFlow 1.1 Python API (一)
Tensor操作
- 切片与融合
操作 | 描述 |
---|---|
tf.slice(input_,begin,size,name=None) | 从tensor中提取一部分切片 # ‘input’ is [[[1, 1, 1], [2, 2, 2]], [[3, 3, 3], [4, 4, 4]], [[5, 5, 5], [6, 6, 6]]] tf.slice(input, [1, 0, 0], [1, 1, 3]) ==> [[[3, 3, 3]]]; tf.slice(input, [1, 0, 0], [1, 2, 3]) ==> [[[3, 3, 3], [4, 4, 4]]]; tf.slice(input, [1, 0, 0], [2, 1, 3]) ==> [[[3, 3, 3]], [[5, 5, 5]]] |
tf.split(value, num_or_size_splits, axis=0, num=None, name=’split’) | 将tensor切割成subtensor,其中当num_or_size_splits为标量的时候,表示沿着axis将tensor均匀分成若干等分,当num_or_size_splits为tensor的时候,表示将tensor沿着axisa按照num_or_size_splits进行分割 # ‘value’ is a tensor with shape [5, 30] # Split ‘value’ into 3 tensors with sizes [4, 15, 11] along dimension 1; split0, split1, split2 = tf.split(value, [4, 15, 11], 1) tf.shape(split0) ==> [5, 4] tf.shape(split1) ==> [5, 15] tf.shape(split2) ==> [5, 11] # Split ‘value’ into 3 tensors along dimension 1 split0, split1, split2 = tf.split(value, num_or_size_splits=3, axis=1) tf.shape(split0) ==> [5, 10] |
tf.pad(tensor,paddings,mode=’CONSTANT’,name=None) | 在原有的矩阵上进行填充 # ‘t’ is [[1, 2, 3], [4, 5, 6]]. # ‘paddings’ is [[1, 1,], [2, 2]]. # rank of ‘t’ is 2. pad(t, paddings, “CONSTANT”) ==> [[0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 2, 3, 0, 0], [0, 0, 4, 5, 6, 0, 0], [0, 0, 0, 0, 0, 0, 0]] pad(t, paddings, “REFLECT”) ==> [[6, 5, 4, 5, 6, 5, |