tf.gather和tf.gather_nd

tf.gather

Gather slices from params axis according to indices.

tf.gather(params, indices, validate_indices=None, axis=None, batch_dims=0, name=None)

Example:

# data: [classes, students, subjects]
data = tf.ones([4,35,8])
print(data.shape)    # TensorShape([4, 35, 8])

# sample several classes
data = tf.gather(data, axis=0, indices=[2,3])
print(data.shape)    # TensorShape([2, 35, 8])

tf.gather_nd

Gather slices from params into a Tensor with shape specified by indices.

tf.gather_nd(params, indices, batch_dims=0, name=None)

Example:

# data: [classes, students, subjects]
data = tf.ones([4,35,8])
print(data.shape)    # TensorShape([4, 35, 8])

# sample several (classes and students)
# for instance: [class1_student1, class2_studnet2, class3_student3, class4_student4]
data = tf.gather_nd(data, [[0,0],[1,1],[2,2],[3,3]])
print(data.shape)    # TensorShape([4, 8])
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值