【问题标题】:Slicing a tensor by using indices in Tensorflow在 Tensorflow 中使用索引对张量进行切片
【发布时间】:2017-06-02 14:25:14
【问题描述】:

基本上我有一个二维数组,我想做这个漂亮的类似 numpy 的东西

noise_spec[:rows,:cols]

在张量流中。这里 rows 和 cols 只是两个整数。

【问题讨论】:

    标签: arrays tensorflow slice


    【解决方案1】:

    确实,TensorFlow 现在对切片有更好的支持,因此您可以使用与 NumPy 完全相同的语法:

    result = noise_spec[:rows, :cols]
    

    【讨论】:

    • 不幸的是,u = U[idx_i,:] 不适用于 tf 1.8.0。 idx_i 是我想选择的行的随机索引。 tf.nn.embedding_lookup 工作。
    【解决方案2】:

    发现了,是

    tf.slice(noise_spec, [0,0],[rows, cols])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      • 2020-02-16
      • 1970-01-01
      • 1970-01-01
      • 2019-04-13
      • 1970-01-01
      • 2016-05-22
      相关资源
      最近更新 更多