tf.gather和tf.gather_nd都是从tensor中取出index标注的部分,不同之处在于,gather一般只使用一个index来标注,而gather_nd可以使用多个index。
例如:
如何直观理解gather_nd的indices呢?
在上例中,直观的理解就是,取出params中位于[0,0]和[1,1]处的tensor,放入index中对应的位置。
换句话说,除去tensor维之外,返回值的形状和indices相同,值由indices标注。
如果理解了这一点,就可以用gather_nd实现gather:
深度理解tf.gather和tf.gather_nd的用法
最新推荐文章于 2022-07-12 17:03:54 发布