将tensor转array
生活随笔
收集整理的這篇文章主要介紹了
将tensor转array
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
如果對tensor使用extend方法,如下面這個例子:
import tensorflow as tfa = tf.convert_to_tensor([1,2,3]) b = [] with tf.Session() as sess:b.extend(a)會報錯“Tensor objects are only iterable when eager execution is enabled. To iterate over this tensor use tf.map_fn.”
需要把tensor轉換為數組,通過tensor.eval()方法來轉換,如下面例子:
a = tf.convert_to_tensor([1,2,3]) b = [] with tf.Session() as sess:c = a.eval()b.extend(c)print(type(c)) # <class 'numpy.ndarray'>注意:這一句要放到sess里面
c = a.eval()?
總結
以上是生活随笔為你收集整理的将tensor转array的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用哈希表的好处
- 下一篇: can't request region