在Tensorflow中,使用Python,如何将张量(Tensor)转换为numpy数组呢?
最佳解决办法
由Session.run或eval返回的任何张量都是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://blog.csdn.net/lcczzu/article/details/91492299