在TensorFlow中如何将Tensor张量转换为numpy数组?

匿名 (未验证) 提交于 2019-12-02 23:42:01

在Tensorflow中,使用Python,如何将张量(Tensor)转换为numpy数组呢?

最佳解决办法

Session.runeval返回的任何张量都是NumPy数组。

 >>> print(type(tf.Session().run(tf.constant([1,2,3])))) <class 'numpy.ndarray'> 

要么:

 >>> sess = tf.InteractiveSession() >>> print(type(tf.constant([1,2,3]).eval())) <class 'numpy.ndarray'> 

或者等同地:

 >>> sess = tf.Session() >>> with sess.as_default(): >>>    print(type(tf.constant([1,2,3]).eval())) <class 'numpy.ndarray'> 

参考资料

--------------------------------------------------------------------------------------------------------------------

https://vimsky.com/article/3725.html

文章来源: https://blog.csdn.net/lcczzu/article/details/91492299
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!