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

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

tensorflow tensor

最佳解决办法

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'>

numpy array数组

参考资料

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

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

猜你喜欢

转载自blog.csdn.net/lcczzu/article/details/91492299