Python – tensorflow.gather()
TensorFlow是谷歌设计的开源Python库,用于开发机器学习模型和深度学习神经网络。
gather()用于根据提供的指数对输入张量进行切片。
语法: tensorflow.gather( params, indices, validate_indices, axis, batch_dims, name)
参数:
- params: 它是一个等级大于或等于axis+1的张量。
- indices: 它是一个dtype int32或int64的张量。它的值应该在[0, params.shape[axis]]的范围内。
- axis: 它是一个dtype int32或int64的张量。它定义了应该收集指数的轴。默认值是0,它必须大于或等于 batch_dims。
- batch_dims: 它是一个整数,代表批次维度的数量。它必须小于或等于rank(indices)。
- name: 它定义了操作的名称。
返回值:
它返回一个张量,其dtype与参数相同。
示例 1:
输出:
示例 2:
输出: