tensor也可以作为索引
生活随笔
收集整理的這篇文章主要介紹了
tensor也可以作为索引
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在TensorFlow中,tensor也可以作為索引,但只能作為同樣為tensor類型變量的索引,不能作為list類型變量的索引如下面的例子:
import tensorflow as tfindex = tf.to_int32([0,1,2]) # index是一個tensor a = [[1,2,3], [4,5,6]] b = a[index[0]] sess = tf.InteractiveSession() print(b)TypeError: list indices must be integers or slices, not Tensor
若將a變為tensor類型
import tensorflow as tfindex = tf.to_int32([0,1,2]) # index是一個tensor a = tf.convert_to_tensor([[1,2,3], [4,5,6]]) b = a[index[0]] sess = tf.InteractiveSession() print(sess.run(b)) # [1 2 3]?
總結
以上是生活随笔為你收集整理的tensor也可以作为索引的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: github注册账号一直验证失败
- 下一篇: 如何使用UR机器人模拟软件URsim