tensorflow2.0切片的几种方式

tensorflow2.0获取某个维度的部分数据,如下:

import tensorflow as tf

a = tf.random.uniform((4, 5))
# 方法一
b = a[::2]
# 方法二
c = tf.boolean_mask(a, [True, False, True, False], axis=0)
# 方法三
d = tf.gather(a, [0, 2], axis=0)


标签: 、面试
  • 回复
隐藏