【问题标题】:Select or slice tensor by a tensor array of random indices?通过随机索引的张量数组选择或切片张量?
【发布时间】:2018-08-05 06:15:24
【问题描述】:

我正在尝试在 TensorFlow 中复制它:

mat = np.matrix("1,2,3;4,5,6;7,8,9")
matrix([[1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]])
mat[2]
matrix([[7, 8, 9]])

我收到此错误:

X_batch = X_train[batch]

IndexError:只有整数、切片 (:)、省略号 (...)、numpy.newaxis (None) 和整数或布尔数组是有效的索引

X_trainbatch_size x (other dimensions)batch 是随机值的一维张量。

我正在尝试从训练集中随机抽取一批(实际上我正在尝试找出如何针对多个 epoch 进行训练,question here)并认为随机张量的索引是可行的方法,但是这不起作用。

【问题讨论】:

    标签: python tensorflow machine-learning slice


    【解决方案1】:

    我想我从这个类似的问题中找到了答案:Tensorflow: Using tf.slice to split the input

    答案似乎是 tf.gather 正是这样做的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-02
      • 1970-01-01
      • 1970-01-01
      • 2019-05-30
      • 2019-05-07
      • 2017-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多